[feature] Implement /api/v2/instance endpoint (#1409)

* interim: start adding /api/v2/instance

* finish up
This commit is contained in:
tobi 2023-02-02 14:08:13 +01:00 committed by GitHub
parent 4ee4cd2da1
commit 382512a5a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
109 changed files with 1660 additions and 944 deletions

View file

@ -160,7 +160,7 @@
// attach global no route / 404 handler to the router // attach global no route / 404 handler to the router
router.AttachNoRouteHandler(func(c *gin.Context) { router.AttachNoRouteHandler(func(c *gin.Context) {
apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(errors.New(http.StatusText(http.StatusNotFound))), processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(errors.New(http.StatusText(http.StatusNotFound))), processor.InstanceGetV1)
}) })
// build router modules // build router modules

View file

@ -99,7 +99,7 @@
// attach global no route / 404 handler to the router // attach global no route / 404 handler to the router
router.AttachNoRouteHandler(func(c *gin.Context) { router.AttachNoRouteHandler(func(c *gin.Context) {
apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(errors.New(http.StatusText(http.StatusNotFound))), processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(errors.New(http.StatusText(http.StatusNotFound))), processor.InstanceGetV1)
}) })
// build router modules // build router modules

View file

@ -4,16 +4,6 @@ definitions:
title: EmojiUpdateType models an admin update action to take on a custom emoji. title: EmojiUpdateType models an admin update action to take on a custom emoji.
type: string type: string
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
InstanceConfigurationAccounts:
properties:
allow_custom_css:
description: Whether or not accounts on this instance are allowed to upload custom CSS for profiles and statuses.
example: false
type: boolean
x-go-name: AllowCustomCSS
title: InstanceConfigurationAccounts models instance account config parameters.
type: object
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
InstanceConfigurationEmojis: InstanceConfigurationEmojis:
properties: properties:
emoji_size_limit: emoji_size_limit:
@ -1127,134 +1117,23 @@ definitions:
type: object type: object
x-go-name: Field x-go-name: Field
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
instance: instanceConfigurationAccounts:
properties: properties:
account_domain: allow_custom_css:
description: |- description: Whether or not accounts on this instance are allowed to upload custom CSS for profiles and statuses.
The domain of accounts on this instance. example: false
This will not necessarily be the same as
simply the Host part of the URI.
example: example.org
type: string
x-go-name: AccountDomain
approval_required:
description: New account registrations require admin approval.
type: boolean type: boolean
x-go-name: ApprovalRequired x-go-name: AllowCustomCSS
configuration: max_featured_tags:
$ref: '#/definitions/instanceConfiguration'
contact_account:
$ref: '#/definitions/account'
description:
description: |- description: |-
Description of the instance. The maximum number of featured tags allowed for each account.
Currently not implemented, so this is hardcoded to 10.
Should be HTML formatted, but might be plaintext. format: int64
This should be displayed on the 'about' page for an instance.
type: string
x-go-name: Description
email:
description: An email address that may be used for inquiries.
example: admin@example.org
type: string
x-go-name: Email
invites_enabled:
description: Invites are enabled on this instance.
type: boolean
x-go-name: InvitesEnabled
languages:
description: Primary language of the instance.
example: en
items:
type: string
type: array
x-go-name: Languages
max_toot_chars:
description: |-
Maximum allowed length of a post on this instance, in characters.
This is provided for compatibility with Tusky and other apps.
example: 5000
format: uint64
type: integer type: integer
x-go-name: MaxTootChars x-go-name: MaxFeaturedTags
registrations: title: InstanceConfigurationAccounts models instance account config parameters.
description: New account registrations are enabled on this instance.
type: boolean
x-go-name: Registrations
short_description:
description: |-
A shorter description of the instance.
Should be HTML formatted, but might be plaintext.
This should be displayed on the instance splash/landing page.
type: string
x-go-name: ShortDescription
stats:
additionalProperties:
format: int64
type: integer
description: 'Statistics about the instance: number of posts, accounts, etc.'
type: object
x-go-name: Stats
thumbnail:
description: URL of the instance avatar/banner image.
example: https://example.org/files/instance/thumbnail.jpeg
type: string
x-go-name: Thumbnail
thumbnail_description:
description: Description of the instance thumbnail.
example: picture of a cute lil' friendly sloth
type: string
x-go-name: ThumbnailDescription
thumbnail_type:
description: MIME type of the instance thumbnail.
example: image/png
type: string
x-go-name: ThumbnailType
title:
description: The title of the instance.
example: GoToSocial Example Instance
type: string
x-go-name: Title
uri:
description: The URI of the instance.
example: https://gts.example.org
type: string
x-go-name: URI
urls:
$ref: '#/definitions/instanceURLs'
version:
description: |-
The version of GoToSocial installed on the instance.
This will contain at least a semantic version number.
It may also contain, after a space, the short git commit ID of the running software.
example: 0.1.1 cb85f65
type: string
x-go-name: Version
title: Instance models information about this or another instance.
type: object type: object
x-go-name: Instance x-go-name: InstanceConfigurationAccounts
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
instanceConfiguration:
properties:
accounts:
$ref: '#/definitions/InstanceConfigurationAccounts'
emojis:
$ref: '#/definitions/InstanceConfigurationEmojis'
media_attachments:
$ref: '#/definitions/instanceConfigurationMediaAttachments'
polls:
$ref: '#/definitions/instanceConfigurationPolls'
statuses:
$ref: '#/definitions/instanceConfigurationStatuses'
title: InstanceConfiguration models instance configuration parameters.
type: object
x-go-name: InstanceConfiguration
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
instanceConfigurationMediaAttachments: instanceConfigurationMediaAttachments:
properties: properties:
@ -1363,16 +1242,362 @@ definitions:
type: object type: object
x-go-name: InstanceConfigurationStatuses x-go-name: InstanceConfigurationStatuses
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
instanceURLs: instanceV1:
properties:
account_domain:
description: |-
The domain of accounts on this instance.
This will not necessarily be the same as
simply the Host part of the URI.
example: example.org
type: string
x-go-name: AccountDomain
approval_required:
description: New account registrations require admin approval.
type: boolean
x-go-name: ApprovalRequired
configuration:
$ref: '#/definitions/instanceV1Configuration'
contact_account:
$ref: '#/definitions/account'
description:
description: |-
Description of the instance.
Should be HTML formatted, but might be plaintext.
This should be displayed on the 'about' page for an instance.
type: string
x-go-name: Description
email:
description: An email address that may be used for inquiries.
example: admin@example.org
type: string
x-go-name: Email
invites_enabled:
description: Invites are enabled on this instance.
type: boolean
x-go-name: InvitesEnabled
languages:
description: Primary language of the instance.
example: en
items:
type: string
type: array
x-go-name: Languages
max_toot_chars:
description: |-
Maximum allowed length of a post on this instance, in characters.
This is provided for compatibility with Tusky and other apps.
example: 5000
format: uint64
type: integer
x-go-name: MaxTootChars
registrations:
description: New account registrations are enabled on this instance.
type: boolean
x-go-name: Registrations
short_description:
description: |-
A shorter description of the instance.
Should be HTML formatted, but might be plaintext.
This should be displayed on the instance splash/landing page.
type: string
x-go-name: ShortDescription
stats:
additionalProperties:
format: int64
type: integer
description: 'Statistics about the instance: number of posts, accounts, etc.'
type: object
x-go-name: Stats
thumbnail:
description: URL of the instance avatar/banner image.
example: https://example.org/files/instance/thumbnail.jpeg
type: string
x-go-name: Thumbnail
thumbnail_description:
description: Description of the instance thumbnail.
example: picture of a cute lil' friendly sloth
type: string
x-go-name: ThumbnailDescription
thumbnail_type:
description: MIME type of the instance thumbnail.
example: image/png
type: string
x-go-name: ThumbnailType
title:
description: The title of the instance.
example: GoToSocial Example Instance
type: string
x-go-name: Title
uri:
description: The URI of the instance.
example: https://gts.example.org
type: string
x-go-name: URI
urls:
$ref: '#/definitions/instanceV1URLs'
version:
description: |-
The version of GoToSocial installed on the instance.
This will contain at least a semantic version number.
It may also contain, after a space, the short git commit ID of the running software.
example: 0.1.1 cb85f65
type: string
x-go-name: Version
title: InstanceV1 models information about this instance.
type: object
x-go-name: InstanceV1
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
instanceV1Configuration:
properties:
accounts:
$ref: '#/definitions/instanceConfigurationAccounts'
emojis:
$ref: '#/definitions/InstanceConfigurationEmojis'
media_attachments:
$ref: '#/definitions/instanceConfigurationMediaAttachments'
polls:
$ref: '#/definitions/instanceConfigurationPolls'
statuses:
$ref: '#/definitions/instanceConfigurationStatuses'
title: InstanceV1Configuration models instance configuration parameters.
type: object
x-go-name: InstanceV1Configuration
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
instanceV1URLs:
properties: properties:
streaming_api: streaming_api:
description: Websockets address for status and notification streaming. description: Websockets address for status and notification streaming.
example: wss://example.org example: wss://example.org
type: string type: string
x-go-name: StreamingAPI x-go-name: StreamingAPI
title: InstanceURLs models instance-relevant URLs for client application consumption. title: InstanceV1URLs models instance-relevant URLs for client application consumption.
type: object type: object
x-go-name: InstanceURLs x-go-name: InstanceV1URLs
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
instanceV2:
properties:
account_domain:
description: |-
The domain of accounts on this instance.
This will not necessarily be the same as
domain.
example: example.org
type: string
x-go-name: AccountDomain
configuration:
$ref: '#/definitions/instanceV2Configuration'
contact:
$ref: '#/definitions/instanceV2Contact'
description:
description: |-
Description of the instance.
Should be HTML formatted, but might be plaintext.
This should be displayed on the 'about' page for an instance.
type: string
x-go-name: Description
domain:
description: The domain of the instance.
example: gts.example.org
type: string
x-go-name: Domain
languages:
description: Primary languages of the instance + moderators/admins.
example:
- en
items:
type: string
type: array
x-go-name: Languages
registrations:
$ref: '#/definitions/instanceV2Registrations'
rules:
description: |-
An itemized list of rules for this website.
Currently not implemented (will always be empty array).
items: {}
type: array
x-go-name: Rules
source_url:
description: The URL for the source code of the software running on this instance, in keeping with AGPL license requirements.
example: https://github.com/superseriousbusiness/gotosocial
type: string
x-go-name: SourceURL
thumbnail:
$ref: '#/definitions/instanceV2Thumbnail'
title:
description: The title of the instance.
example: GoToSocial Example Instance
type: string
x-go-name: Title
usage:
$ref: '#/definitions/instanceV2Usage'
version:
description: |-
The version of GoToSocial installed on the instance.
This will contain at least a semantic version number.
It may also contain, after a space, the short git commit ID of the running software.
example: 0.1.1 cb85f65
type: string
x-go-name: Version
title: InstanceV2 models information about this instance.
type: object
x-go-name: InstanceV2
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
instanceV2Configuration:
properties:
accounts:
$ref: '#/definitions/instanceConfigurationAccounts'
emojis:
$ref: '#/definitions/InstanceConfigurationEmojis'
media_attachments:
$ref: '#/definitions/instanceConfigurationMediaAttachments'
polls:
$ref: '#/definitions/instanceConfigurationPolls'
statuses:
$ref: '#/definitions/instanceConfigurationStatuses'
translation:
$ref: '#/definitions/instanceV2ConfigurationTranslation'
urls:
$ref: '#/definitions/instanceV1URLs'
title: Configured values and limits for this instance.
type: object
x-go-name: InstanceV2Configuration
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
instanceV2ConfigurationTranslation:
properties:
enabled:
description: |-
Whether the Translations API is available on this instance.
Not implemented so this value is always false.
type: boolean
x-go-name: Enabled
title: Hints related to translation.
type: object
x-go-name: InstanceV2ConfigurationTranslation
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
instanceV2Contact:
properties:
account:
$ref: '#/definitions/account'
email:
description: |-
An email address that can be messaged regarding inquiries or issues.
Empty string if no email address set.
example: someone@example.org
type: string
x-go-name: Email
title: Hints related to contacting a representative of the instance.
type: object
x-go-name: InstanceV2Contact
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
instanceV2Registrations:
properties:
approval_required:
description: Whether registrations require moderator approval.
example: true
type: boolean
x-go-name: ApprovalRequired
enabled:
description: Whether registrations are enabled.
example: false
type: boolean
x-go-name: Enabled
message:
description: |-
A custom message (html string) to be shown when registrations are closed.
Value will be null if no message is set.
example: <p>Registrations are currently closed on example.org because of spam bots!</p>
type: string
x-go-name: Message
title: Information about registering for this instance.
type: object
x-go-name: InstanceV2Registrations
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
instanceV2Thumbnail:
properties:
blurhash:
description: |-
A hash computed by the BlurHash algorithm, for generating colorful preview thumbnails when media has not been downloaded yet.
Key/value not set if no blurhash available.
example: UeKUpFxuo~R%0nW;WCnhF6RjaJt757oJodS$
type: string
x-go-name: Blurhash
thumbnail_description:
description: |-
Description of the instance thumbnail.
Key/value not set if no description available.
example: picture of a cute lil' friendly sloth
type: string
x-go-name: Description
thumbnail_type:
description: |-
MIME type of the instance thumbnail.
Key/value not set if thumbnail image type unknown.
example: image/png
type: string
x-go-name: Type
url:
description: The URL for the thumbnail image.
example: https://example.org/fileserver/01BPSX2MKCRVMD4YN4D71G9CP5/attachment/original/01H88X0KQ2DFYYDSWYP93VDJZA.png
type: string
x-go-name: URL
versions:
$ref: '#/definitions/instanceV2ThumbnailVersions'
title: An image used to represent this instance.
type: object
x-go-name: InstanceV2Thumbnail
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
instanceV2ThumbnailVersions:
properties:
'@1x':
description: |-
The URL for the thumbnail image at 1x resolution.
Key/value not set if scaled versions not available.
type: string
x-go-name: Size1URL
'@2x':
description: |-
The URL for the thumbnail image at 2x resolution.
Key/value not set if scaled versions not available.
type: string
x-go-name: Size2URL
title: Links to scaled resolution images, for high DPI screens.
type: object
x-go-name: InstanceV2ThumbnailVersions
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
instanceV2Usage:
properties:
users:
$ref: '#/definitions/instanceV2Users'
title: Usage data for this instance.
type: object
x-go-name: InstanceV2Usage
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
instanceV2Users:
properties:
active_month:
description: |-
The number of active users in the past 4 weeks.
Currently not implemented: will always be 0.
example: 0
format: int64
type: integer
x-go-name: ActiveMonth
title: Usage data related to users on this instance.
type: object
x-go-name: InstanceV2Users
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
mediaDimensions: mediaDimensions:
properties: properties:
@ -3920,14 +4145,14 @@ paths:
- follow_requests - follow_requests
/api/v1/instance: /api/v1/instance:
get: get:
operationId: instanceGet operationId: instanceGetV1
produces: produces:
- application/json - application/json
responses: responses:
"200": "200":
description: Instance information. description: Instance information.
schema: schema:
$ref: '#/definitions/instance' $ref: '#/definitions/instanceV1'
"406": "406":
description: not acceptable description: not acceptable
"500": "500":
@ -5269,6 +5494,23 @@ paths:
summary: Change the password of authenticated user. summary: Change the password of authenticated user.
tags: tags:
- user - user
/api/v2/instance:
get:
operationId: instanceGetV2
produces:
- application/json
responses:
"200":
description: Instance information.
schema:
$ref: '#/definitions/instanceV2'
"406":
description: not acceptable
"500":
description: internal error
summary: View instance information.
tags:
- instance
/nodeinfo/2.0: /nodeinfo/2.0:
get: get:
description: 'See: https://nodeinfo.diaspora.software/schema.html' description: 'See: https://nodeinfo.diaspora.software/schema.html'

View file

@ -33,25 +33,25 @@ func (m *Module) EmojiGetHandler(c *gin.Context) {
requestedEmojiID := strings.ToUpper(c.Param(EmojiIDKey)) requestedEmojiID := strings.ToUpper(c.Param(EmojiIDKey))
if requestedEmojiID == "" { if requestedEmojiID == "" {
err := errors.New("no emoji id specified in request") err := errors.New("no emoji id specified in request")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
format, err := apiutil.NegotiateAccept(c, apiutil.ActivityPubAcceptHeaders...) format, err := apiutil.NegotiateAccept(c, apiutil.ActivityPubAcceptHeaders...)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
resp, errWithCode := m.processor.GetFediEmoji(apiutil.TransferSignatureContext(c), requestedEmojiID, c.Request.URL) resp, errWithCode := m.processor.GetFediEmoji(apiutil.TransferSignatureContext(c), requestedEmojiID, c.Request.URL)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
b, err := json.Marshal(resp) b, err := json.Marshal(resp)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1)
return return
} }

View file

@ -35,13 +35,13 @@ func (m *Module) FollowersGETHandler(c *gin.Context) {
requestedUsername := strings.ToLower(c.Param(UsernameKey)) requestedUsername := strings.ToLower(c.Param(UsernameKey))
if requestedUsername == "" { if requestedUsername == "" {
err := errors.New("no username specified in request") err := errors.New("no username specified in request")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
format, err := apiutil.NegotiateAccept(c, apiutil.HTMLOrActivityPubHeaders...) format, err := apiutil.NegotiateAccept(c, apiutil.HTMLOrActivityPubHeaders...)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -53,13 +53,13 @@ func (m *Module) FollowersGETHandler(c *gin.Context) {
resp, errWithCode := m.processor.GetFediFollowers(apiutil.TransferSignatureContext(c), requestedUsername, c.Request.URL) resp, errWithCode := m.processor.GetFediFollowers(apiutil.TransferSignatureContext(c), requestedUsername, c.Request.URL)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
b, err := json.Marshal(resp) b, err := json.Marshal(resp)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1)
return return
} }

View file

@ -35,13 +35,13 @@ func (m *Module) FollowingGETHandler(c *gin.Context) {
requestedUsername := strings.ToLower(c.Param(UsernameKey)) requestedUsername := strings.ToLower(c.Param(UsernameKey))
if requestedUsername == "" { if requestedUsername == "" {
err := errors.New("no username specified in request") err := errors.New("no username specified in request")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
format, err := apiutil.NegotiateAccept(c, apiutil.HTMLOrActivityPubHeaders...) format, err := apiutil.NegotiateAccept(c, apiutil.HTMLOrActivityPubHeaders...)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -53,13 +53,13 @@ func (m *Module) FollowingGETHandler(c *gin.Context) {
resp, errWithCode := m.processor.GetFediFollowing(apiutil.TransferSignatureContext(c), requestedUsername, c.Request.URL) resp, errWithCode := m.processor.GetFediFollowing(apiutil.TransferSignatureContext(c), requestedUsername, c.Request.URL)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
b, err := json.Marshal(resp) b, err := json.Marshal(resp)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1)
return return
} }

View file

@ -34,18 +34,18 @@ func (m *Module) InboxPOSTHandler(c *gin.Context) {
requestedUsername := strings.ToLower(c.Param(UsernameKey)) requestedUsername := strings.ToLower(c.Param(UsernameKey))
if requestedUsername == "" { if requestedUsername == "" {
err := errors.New("no username specified in request") err := errors.New("no username specified in request")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if posted, err := m.processor.InboxPost(apiutil.TransferSignatureContext(c), c.Writer, c.Request); err != nil { if posted, err := m.processor.InboxPost(apiutil.TransferSignatureContext(c), c.Writer, c.Request); err != nil {
if withCode, ok := err.(gtserror.WithCode); ok { if withCode, ok := err.(gtserror.WithCode); ok {
apiutil.ErrorHandler(c, withCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, withCode, m.processor.InstanceGetV1)
} else { } else {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
} }
} else if !posted { } else if !posted {
err := errors.New("unable to process request") err := errors.New("unable to process request")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
} }
} }

View file

@ -90,13 +90,13 @@ func (m *Module) OutboxGETHandler(c *gin.Context) {
requestedUsername := strings.ToLower(c.Param(UsernameKey)) requestedUsername := strings.ToLower(c.Param(UsernameKey))
if requestedUsername == "" { if requestedUsername == "" {
err := errors.New("no username specified in request") err := errors.New("no username specified in request")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
format, err := apiutil.NegotiateAccept(c, apiutil.HTMLOrActivityPubHeaders...) format, err := apiutil.NegotiateAccept(c, apiutil.HTMLOrActivityPubHeaders...)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -111,7 +111,7 @@ func (m *Module) OutboxGETHandler(c *gin.Context) {
i, err := strconv.ParseBool(pageString) i, err := strconv.ParseBool(pageString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", PageKey, err) err := fmt.Errorf("error parsing %s: %s", PageKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
page = i page = i
@ -131,13 +131,13 @@ func (m *Module) OutboxGETHandler(c *gin.Context) {
resp, errWithCode := m.processor.GetFediOutbox(apiutil.TransferSignatureContext(c), requestedUsername, page, maxID, minID, c.Request.URL) resp, errWithCode := m.processor.GetFediOutbox(apiutil.TransferSignatureContext(c), requestedUsername, page, maxID, minID, c.Request.URL)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
b, err := json.Marshal(resp) b, err := json.Marshal(resp)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1)
return return
} }

View file

@ -39,13 +39,13 @@ func (m *Module) PublicKeyGETHandler(c *gin.Context) {
requestedUsername := strings.ToLower(c.Param(UsernameKey)) requestedUsername := strings.ToLower(c.Param(UsernameKey))
if requestedUsername == "" { if requestedUsername == "" {
err := errors.New("no username specified in request") err := errors.New("no username specified in request")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
format, err := apiutil.NegotiateAccept(c, apiutil.HTMLOrActivityPubHeaders...) format, err := apiutil.NegotiateAccept(c, apiutil.HTMLOrActivityPubHeaders...)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -57,13 +57,13 @@ func (m *Module) PublicKeyGETHandler(c *gin.Context) {
resp, errWithCode := m.processor.GetFediUser(apiutil.TransferSignatureContext(c), requestedUsername, c.Request.URL) resp, errWithCode := m.processor.GetFediUser(apiutil.TransferSignatureContext(c), requestedUsername, c.Request.URL)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
b, err := json.Marshal(resp) b, err := json.Marshal(resp)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1)
return return
} }

View file

@ -97,7 +97,7 @@ func (m *Module) StatusRepliesGETHandler(c *gin.Context) {
requestedUsername := strings.ToLower(c.Param(UsernameKey)) requestedUsername := strings.ToLower(c.Param(UsernameKey))
if requestedUsername == "" { if requestedUsername == "" {
err := errors.New("no username specified in request") err := errors.New("no username specified in request")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -105,13 +105,13 @@ func (m *Module) StatusRepliesGETHandler(c *gin.Context) {
requestedStatusID := strings.ToUpper(c.Param(StatusIDKey)) requestedStatusID := strings.ToUpper(c.Param(StatusIDKey))
if requestedStatusID == "" { if requestedStatusID == "" {
err := errors.New("no status id specified in request") err := errors.New("no status id specified in request")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
format, err := apiutil.NegotiateAccept(c, apiutil.HTMLOrActivityPubHeaders...) format, err := apiutil.NegotiateAccept(c, apiutil.HTMLOrActivityPubHeaders...)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -126,7 +126,7 @@ func (m *Module) StatusRepliesGETHandler(c *gin.Context) {
i, err := strconv.ParseBool(pageString) i, err := strconv.ParseBool(pageString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", PageKey, err) err := fmt.Errorf("error parsing %s: %s", PageKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
page = i page = i
@ -138,7 +138,7 @@ func (m *Module) StatusRepliesGETHandler(c *gin.Context) {
i, err := strconv.ParseBool(onlyOtherAccountsString) i, err := strconv.ParseBool(onlyOtherAccountsString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", OnlyOtherAccountsKey, err) err := fmt.Errorf("error parsing %s: %s", OnlyOtherAccountsKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
onlyOtherAccounts = i onlyOtherAccounts = i
@ -152,13 +152,13 @@ func (m *Module) StatusRepliesGETHandler(c *gin.Context) {
resp, errWithCode := m.processor.GetFediStatusReplies(apiutil.TransferSignatureContext(c), requestedUsername, requestedStatusID, page, onlyOtherAccounts, minID, c.Request.URL) resp, errWithCode := m.processor.GetFediStatusReplies(apiutil.TransferSignatureContext(c), requestedUsername, requestedStatusID, page, onlyOtherAccounts, minID, c.Request.URL)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
b, err := json.Marshal(resp) b, err := json.Marshal(resp)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1)
return return
} }

View file

@ -35,7 +35,7 @@ func (m *Module) StatusGETHandler(c *gin.Context) {
requestedUsername := strings.ToLower(c.Param(UsernameKey)) requestedUsername := strings.ToLower(c.Param(UsernameKey))
if requestedUsername == "" { if requestedUsername == "" {
err := errors.New("no username specified in request") err := errors.New("no username specified in request")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -43,13 +43,13 @@ func (m *Module) StatusGETHandler(c *gin.Context) {
requestedStatusID := strings.ToUpper(c.Param(StatusIDKey)) requestedStatusID := strings.ToUpper(c.Param(StatusIDKey))
if requestedStatusID == "" { if requestedStatusID == "" {
err := errors.New("no status id specified in request") err := errors.New("no status id specified in request")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
format, err := apiutil.NegotiateAccept(c, apiutil.HTMLOrActivityPubHeaders...) format, err := apiutil.NegotiateAccept(c, apiutil.HTMLOrActivityPubHeaders...)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -61,13 +61,13 @@ func (m *Module) StatusGETHandler(c *gin.Context) {
resp, errWithCode := m.processor.GetFediStatus(apiutil.TransferSignatureContext(c), requestedUsername, requestedStatusID, c.Request.URL) resp, errWithCode := m.processor.GetFediStatus(apiutil.TransferSignatureContext(c), requestedUsername, requestedStatusID, c.Request.URL)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
b, err := json.Marshal(resp) b, err := json.Marshal(resp)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1)
return return
} }

View file

@ -43,13 +43,13 @@ func (m *Module) UsersGETHandler(c *gin.Context) {
requestedUsername := strings.ToLower(c.Param(UsernameKey)) requestedUsername := strings.ToLower(c.Param(UsernameKey))
if requestedUsername == "" { if requestedUsername == "" {
err := errors.New("no username specified in request") err := errors.New("no username specified in request")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
format, err := apiutil.NegotiateAccept(c, apiutil.HTMLOrActivityPubHeaders...) format, err := apiutil.NegotiateAccept(c, apiutil.HTMLOrActivityPubHeaders...)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -61,13 +61,13 @@ func (m *Module) UsersGETHandler(c *gin.Context) {
resp, errWithCode := m.processor.GetFediUser(apiutil.TransferSignatureContext(c), requestedUsername, c.Request.URL) resp, errWithCode := m.processor.GetFediUser(apiutil.TransferSignatureContext(c), requestedUsername, c.Request.URL)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
b, err := json.Marshal(resp) b, err := json.Marshal(resp)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1)
return return
} }

View file

@ -29,7 +29,6 @@
"github.com/google/uuid" "github.com/google/uuid"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util" apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
@ -43,7 +42,7 @@ func (m *Module) AuthorizeGETHandler(c *gin.Context) {
s := sessions.Default(c) s := sessions.Default(c)
if _, err := apiutil.NegotiateAccept(c, apiutil.HTMLAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.HTMLAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -54,13 +53,13 @@ func (m *Module) AuthorizeGETHandler(c *gin.Context) {
form := &apimodel.OAuthAuthorize{} form := &apimodel.OAuthAuthorize{}
if err := c.ShouldBind(form); err != nil { if err := c.ShouldBind(form); err != nil {
m.clearSession(s) m.clearSession(s)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGetV1)
return return
} }
if errWithCode := saveAuthFormToSession(s, form); errWithCode != nil { if errWithCode := saveAuthFormToSession(s, form); errWithCode != nil {
m.clearSession(s) m.clearSession(s)
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
@ -73,7 +72,7 @@ func (m *Module) AuthorizeGETHandler(c *gin.Context) {
if !ok || clientID == "" { if !ok || clientID == "" {
m.clearSession(s) m.clearSession(s)
err := fmt.Errorf("key %s was not found in session", sessionClientID) err := fmt.Errorf("key %s was not found in session", sessionClientID)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGetV1)
return return
} }
@ -87,7 +86,7 @@ func (m *Module) AuthorizeGETHandler(c *gin.Context) {
} else { } else {
errWithCode = gtserror.NewErrorInternalError(err, safe, oauth.HelpfulAdvice) errWithCode = gtserror.NewErrorInternalError(err, safe, oauth.HelpfulAdvice)
} }
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
@ -101,7 +100,7 @@ func (m *Module) AuthorizeGETHandler(c *gin.Context) {
} else { } else {
errWithCode = gtserror.NewErrorInternalError(err, safe, oauth.HelpfulAdvice) errWithCode = gtserror.NewErrorInternalError(err, safe, oauth.HelpfulAdvice)
} }
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
@ -115,7 +114,7 @@ func (m *Module) AuthorizeGETHandler(c *gin.Context) {
} else { } else {
errWithCode = gtserror.NewErrorInternalError(err, safe, oauth.HelpfulAdvice) errWithCode = gtserror.NewErrorInternalError(err, safe, oauth.HelpfulAdvice)
} }
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
@ -128,7 +127,7 @@ func (m *Module) AuthorizeGETHandler(c *gin.Context) {
if !ok || redirect == "" { if !ok || redirect == "" {
m.clearSession(s) m.clearSession(s)
err := fmt.Errorf("key %s was not found in session", sessionRedirectURI) err := fmt.Errorf("key %s was not found in session", sessionRedirectURI)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGetV1)
return return
} }
@ -136,13 +135,13 @@ func (m *Module) AuthorizeGETHandler(c *gin.Context) {
if !ok || scope == "" { if !ok || scope == "" {
m.clearSession(s) m.clearSession(s)
err := fmt.Errorf("key %s was not found in session", sessionScope) err := fmt.Errorf("key %s was not found in session", sessionScope)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGetV1)
return return
} }
instance, errWithCode := m.processor.InstanceGet(c.Request.Context(), config.GetHost()) instance, errWithCode := m.processor.InstanceGetV1(c.Request.Context())
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
@ -206,7 +205,7 @@ func (m *Module) AuthorizePOSTHandler(c *gin.Context) {
if len(errs) != 0 { if len(errs) != 0 {
errs = append(errs, oauth.HelpfulAdvice) errs = append(errs, oauth.HelpfulAdvice)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(errors.New("one or more missing keys on session during AuthorizePOSTHandler"), errs...), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(errors.New("one or more missing keys on session during AuthorizePOSTHandler"), errs...), m.processor.InstanceGetV1)
return return
} }
@ -220,7 +219,7 @@ func (m *Module) AuthorizePOSTHandler(c *gin.Context) {
} else { } else {
errWithCode = gtserror.NewErrorInternalError(err, safe, oauth.HelpfulAdvice) errWithCode = gtserror.NewErrorInternalError(err, safe, oauth.HelpfulAdvice)
} }
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
@ -234,7 +233,7 @@ func (m *Module) AuthorizePOSTHandler(c *gin.Context) {
} else { } else {
errWithCode = gtserror.NewErrorInternalError(err, safe, oauth.HelpfulAdvice) errWithCode = gtserror.NewErrorInternalError(err, safe, oauth.HelpfulAdvice)
} }
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
@ -263,7 +262,7 @@ func (m *Module) AuthorizePOSTHandler(c *gin.Context) {
} }
if errWithCode := m.processor.OAuthHandleAuthorizeRequest(c.Writer, c.Request); errWithCode != nil { if errWithCode := m.processor.OAuthHandleAuthorizeRequest(c.Writer, c.Request); errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
} }
} }

View file

@ -49,7 +49,7 @@ type extraInfo struct {
func (m *Module) CallbackGETHandler(c *gin.Context) { func (m *Module) CallbackGETHandler(c *gin.Context) {
if !config.GetOIDCEnabled() { if !config.GetOIDCEnabled() {
err := errors.New("oidc is not enabled for this server") err := errors.New("oidc is not enabled for this server")
apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -62,7 +62,7 @@ func (m *Module) CallbackGETHandler(c *gin.Context) {
if returnedInternalState == "" { if returnedInternalState == "" {
m.clearSession(s) m.clearSession(s)
err := fmt.Errorf("%s parameter not found on callback query", callbackStateParam) err := fmt.Errorf("%s parameter not found on callback query", callbackStateParam)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -71,14 +71,14 @@ func (m *Module) CallbackGETHandler(c *gin.Context) {
if !ok { if !ok {
m.clearSession(s) m.clearSession(s)
err := fmt.Errorf("key %s was not found in session", sessionInternalState) err := fmt.Errorf("key %s was not found in session", sessionInternalState)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if returnedInternalState != savedInternalState { if returnedInternalState != savedInternalState {
m.clearSession(s) m.clearSession(s)
err := errors.New("mismatch between callback state and saved state") err := errors.New("mismatch between callback state and saved state")
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -87,14 +87,14 @@ func (m *Module) CallbackGETHandler(c *gin.Context) {
if code == "" { if code == "" {
m.clearSession(s) m.clearSession(s)
err := fmt.Errorf("%s parameter not found on callback query", callbackCodeParam) err := fmt.Errorf("%s parameter not found on callback query", callbackCodeParam)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
claims, errWithCode := m.idp.HandleCallback(c.Request.Context(), code) claims, errWithCode := m.idp.HandleCallback(c.Request.Context(), code)
if errWithCode != nil { if errWithCode != nil {
m.clearSession(s) m.clearSession(s)
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
@ -104,7 +104,7 @@ func (m *Module) CallbackGETHandler(c *gin.Context) {
if !ok || clientID == "" { if !ok || clientID == "" {
m.clearSession(s) m.clearSession(s)
err := fmt.Errorf("key %s was not found in session", sessionClientID) err := fmt.Errorf("key %s was not found in session", sessionClientID)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGetV1)
return return
} }
@ -118,21 +118,21 @@ func (m *Module) CallbackGETHandler(c *gin.Context) {
} else { } else {
errWithCode = gtserror.NewErrorInternalError(err, safe, oauth.HelpfulAdvice) errWithCode = gtserror.NewErrorInternalError(err, safe, oauth.HelpfulAdvice)
} }
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
user, errWithCode := m.fetchUserForClaims(c.Request.Context(), claims, net.IP(c.ClientIP()), app.ID) user, errWithCode := m.fetchUserForClaims(c.Request.Context(), claims, net.IP(c.ClientIP()), app.ID)
if errWithCode != nil { if errWithCode != nil {
m.clearSession(s) m.clearSession(s)
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
if user == nil { if user == nil {
// no user exists yet - let's ask them for their preferred username // no user exists yet - let's ask them for their preferred username
instance, errWithCode := m.processor.InstanceGet(c.Request.Context(), config.GetHost()) instance, errWithCode := m.processor.InstanceGetV1(c.Request.Context())
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
@ -141,7 +141,7 @@ func (m *Module) CallbackGETHandler(c *gin.Context) {
s.Set(sessionAppID, app.ID) s.Set(sessionAppID, app.ID)
if err := s.Save(); err != nil { if err := s.Save(); err != nil {
m.clearSession(s) m.clearSession(s)
apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1)
return return
} }
c.HTML(http.StatusOK, "finalize.tmpl", gin.H{ c.HTML(http.StatusOK, "finalize.tmpl", gin.H{
@ -154,7 +154,7 @@ func (m *Module) CallbackGETHandler(c *gin.Context) {
s.Set(sessionUserID, user.ID) s.Set(sessionUserID, user.ID)
if err := s.Save(); err != nil { if err := s.Save(); err != nil {
m.clearSession(s) m.clearSession(s)
apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1)
return return
} }
c.Redirect(http.StatusFound, "/oauth"+OauthAuthorizePath) c.Redirect(http.StatusFound, "/oauth"+OauthAuthorizePath)
@ -167,15 +167,15 @@ func (m *Module) FinalizePOSTHandler(c *gin.Context) {
form := &extraInfo{} form := &extraInfo{}
if err := c.ShouldBind(form); err != nil { if err := c.ShouldBind(form); err != nil {
m.clearSession(s) m.clearSession(s)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGetV1)
return return
} }
// since we have multiple possible validation error, `validationError` is a shorthand for rendering them // since we have multiple possible validation error, `validationError` is a shorthand for rendering them
validationError := func(err error) { validationError := func(err error) {
instance, errWithCode := m.processor.InstanceGet(c.Request.Context(), config.GetHost()) instance, errWithCode := m.processor.InstanceGetV1(c.Request.Context())
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
c.HTML(http.StatusOK, "finalize.tmpl", gin.H{ c.HTML(http.StatusOK, "finalize.tmpl", gin.H{
@ -195,7 +195,7 @@ func (m *Module) FinalizePOSTHandler(c *gin.Context) {
// see if the username is still available // see if the username is still available
usernameAvailable, err := m.db.IsUsernameAvailable(c.Request.Context(), form.Username) usernameAvailable, err := m.db.IsUsernameAvailable(c.Request.Context(), form.Username)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGetV1)
return return
} }
if !usernameAvailable { if !usernameAvailable {
@ -207,7 +207,7 @@ func (m *Module) FinalizePOSTHandler(c *gin.Context) {
appID, ok := s.Get(sessionAppID).(string) appID, ok := s.Get(sessionAppID).(string)
if !ok { if !ok {
err := fmt.Errorf("key %s was not found in session", sessionAppID) err := fmt.Errorf("key %s was not found in session", sessionAppID)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGetV1)
return return
} }
@ -215,7 +215,7 @@ func (m *Module) FinalizePOSTHandler(c *gin.Context) {
claims, ok := s.Get(sessionClaims).(*oidc.Claims) claims, ok := s.Get(sessionClaims).(*oidc.Claims)
if !ok { if !ok {
err := fmt.Errorf("key %s was not found in session", sessionClaims) err := fmt.Errorf("key %s was not found in session", sessionClaims)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGetV1)
return return
} }
@ -223,7 +223,7 @@ func (m *Module) FinalizePOSTHandler(c *gin.Context) {
user, errWithCode := m.createUserFromOIDC(c.Request.Context(), claims, form, net.IP(c.ClientIP()), appID) user, errWithCode := m.createUserFromOIDC(c.Request.Context(), claims, form, net.IP(c.ClientIP()), appID)
if errWithCode != nil { if errWithCode != nil {
m.clearSession(s) m.clearSession(s)
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
s.Delete(sessionClaims) s.Delete(sessionClaims)
@ -231,7 +231,7 @@ func (m *Module) FinalizePOSTHandler(c *gin.Context) {
s.Set(sessionUserID, user.ID) s.Set(sessionUserID, user.ID)
if err := s.Save(); err != nil { if err := s.Save(); err != nil {
m.clearSession(s) m.clearSession(s)
apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1)
return return
} }
c.Redirect(http.StatusFound, "/oauth"+OauthAuthorizePath) c.Redirect(http.StatusFound, "/oauth"+OauthAuthorizePath)

View file

@ -28,21 +28,19 @@
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util" apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/oauth" "github.com/superseriousbusiness/gotosocial/internal/oauth"
) )
func (m *Module) OobHandler(c *gin.Context) { func (m *Module) OobHandler(c *gin.Context) {
host := config.GetHost() instance, errWithCode := m.processor.InstanceGetV1(c.Request.Context())
instance, errWithCode := m.processor.InstanceGet(c.Request.Context(), host)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
instanceGet := func(ctx context.Context, domain string) (*apimodel.Instance, gtserror.WithCode) { instanceGet := func(ctx context.Context) (*apimodel.InstanceV1, gtserror.WithCode) {
return instance, nil return instance, nil
} }
@ -69,7 +67,7 @@ func (m *Module) OobHandler(c *gin.Context) {
if len(errs) != 0 { if len(errs) != 0 {
errs = append(errs, oauth.HelpfulAdvice) errs = append(errs, oauth.HelpfulAdvice)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(errors.New("one or more missing keys on session during OobHandler"), errs...), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(errors.New("one or more missing keys on session during OobHandler"), errs...), m.processor.InstanceGetV1)
return return
} }

View file

@ -45,14 +45,14 @@ type login struct {
// If an idp provider is set, then the user will be redirected to that to do their sign in. // If an idp provider is set, then the user will be redirected to that to do their sign in.
func (m *Module) SignInGETHandler(c *gin.Context) { func (m *Module) SignInGETHandler(c *gin.Context) {
if _, err := apiutil.NegotiateAccept(c, apiutil.HTMLAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.HTMLAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !config.GetOIDCEnabled() { if !config.GetOIDCEnabled() {
instance, errWithCode := m.processor.InstanceGet(c.Request.Context(), config.GetHost()) instance, errWithCode := m.processor.InstanceGetV1(c.Request.Context())
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
@ -71,7 +71,7 @@ func (m *Module) SignInGETHandler(c *gin.Context) {
if !ok { if !ok {
m.clearSession(s) m.clearSession(s)
err := fmt.Errorf("key %s was not found in session", sessionInternalState) err := fmt.Errorf("key %s was not found in session", sessionInternalState)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -87,7 +87,7 @@ func (m *Module) SignInPOSTHandler(c *gin.Context) {
form := &login{} form := &login{}
if err := c.ShouldBind(form); err != nil { if err := c.ShouldBind(form); err != nil {
m.clearSession(s) m.clearSession(s)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, oauth.HelpfulAdvice), m.processor.InstanceGetV1)
return return
} }
@ -95,14 +95,14 @@ func (m *Module) SignInPOSTHandler(c *gin.Context) {
if errWithCode != nil { if errWithCode != nil {
// don't clear session here, so the user can just press back and try again // don't clear session here, so the user can just press back and try again
// if they accidentally gave the wrong password or something // if they accidentally gave the wrong password or something
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
s.Set(sessionUserID, userid) s.Set(sessionUserID, userid)
if err := s.Save(); err != nil { if err := s.Save(); err != nil {
err := fmt.Errorf("error saving user id onto session: %s", err) err := fmt.Errorf("error saving user id onto session: %s", err)
apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err, oauth.HelpfulAdvice), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err, oauth.HelpfulAdvice), m.processor.InstanceGetV1)
} }
c.Redirect(http.StatusFound, "/oauth"+OauthAuthorizePath) c.Redirect(http.StatusFound, "/oauth"+OauthAuthorizePath)

View file

@ -42,7 +42,7 @@ type tokenRequestForm struct {
// The idea here is to serve an oauth access token to a user, which can be used for authorizing against non-public APIs. // The idea here is to serve an oauth access token to a user, which can be used for authorizing against non-public APIs.
func (m *Module) TokenPOSTHandler(c *gin.Context) { func (m *Module) TokenPOSTHandler(c *gin.Context) {
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }

View file

@ -73,23 +73,23 @@
func (m *Module) AccountCreatePOSTHandler(c *gin.Context) { func (m *Module) AccountCreatePOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, false, false) authed, err := oauth.Authed(c, true, true, false, false)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form := &apimodel.AccountCreateRequest{} form := &apimodel.AccountCreateRequest{}
if err := c.ShouldBind(form); err != nil { if err := c.ShouldBind(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if err := validateCreateAccount(form); err != nil { if err := validateCreateAccount(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -97,14 +97,14 @@ func (m *Module) AccountCreatePOSTHandler(c *gin.Context) {
signUpIP := net.ParseIP(clientIP) signUpIP := net.ParseIP(clientIP)
if signUpIP == nil { if signUpIP == nil {
err := errors.New("ip address could not be parsed from request") err := errors.New("ip address could not be parsed from request")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form.IP = signUpIP form.IP = signUpIP
ti, errWithCode := m.processor.AccountCreate(c.Request.Context(), authed, form) ti, errWithCode := m.processor.AccountCreate(c.Request.Context(), authed, form)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -68,26 +68,26 @@
func (m *Module) AccountDeletePOSTHandler(c *gin.Context) { func (m *Module) AccountDeletePOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form := &apimodel.AccountDeleteRequest{} form := &apimodel.AccountDeleteRequest{}
if err := c.ShouldBind(&form); err != nil { if err := c.ShouldBind(&form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if form.Password == "" { if form.Password == "" {
err = errors.New("no password provided in account delete request") err = errors.New("no password provided in account delete request")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form.DeleteOriginID = authed.Account.ID form.DeleteOriginID = authed.Account.ID
if errWithCode := m.processor.AccountDeleteLocal(c.Request.Context(), authed, form); errWithCode != nil { if errWithCode := m.processor.AccountDeleteLocal(c.Request.Context(), authed, form); errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -69,25 +69,25 @@
func (m *Module) AccountGETHandler(c *gin.Context) { func (m *Module) AccountGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetAcctID := c.Param(IDKey) targetAcctID := c.Param(IDKey)
if targetAcctID == "" { if targetAcctID == "" {
err := errors.New("no account id specified") err := errors.New("no account id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
acctInfo, errWithCode := m.processor.AccountGet(c.Request.Context(), authed, targetAcctID) acctInfo, errWithCode := m.processor.AccountGet(c.Request.Context(), authed, targetAcctID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -138,24 +138,24 @@
func (m *Module) AccountUpdateCredentialsPATCHHandler(c *gin.Context) { func (m *Module) AccountUpdateCredentialsPATCHHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form, err := parseUpdateAccountForm(c) form, err := parseUpdateAccountForm(c)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
acctSensitive, errWithCode := m.processor.AccountUpdate(c.Request.Context(), authed, form) acctSensitive, errWithCode := m.processor.AccountUpdate(c.Request.Context(), authed, form)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -59,18 +59,18 @@
func (m *Module) AccountVerifyGETHandler(c *gin.Context) { func (m *Module) AccountVerifyGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
acctSensitive, errWithCode := m.processor.AccountGet(c.Request.Context(), authed, authed.Account.ID) acctSensitive, errWithCode := m.processor.AccountGet(c.Request.Context(), authed, authed.Account.ID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -69,25 +69,25 @@
func (m *Module) AccountBlockPOSTHandler(c *gin.Context) { func (m *Module) AccountBlockPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetAcctID := c.Param(IDKey) targetAcctID := c.Param(IDKey)
if targetAcctID == "" { if targetAcctID == "" {
err := errors.New("no account id specified") err := errors.New("no account id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
relationship, errWithCode := m.processor.AccountBlockCreate(c.Request.Context(), authed, targetAcctID) relationship, errWithCode := m.processor.AccountBlockCreate(c.Request.Context(), authed, targetAcctID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -91,32 +91,32 @@
func (m *Module) AccountFollowPOSTHandler(c *gin.Context) { func (m *Module) AccountFollowPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetAcctID := c.Param(IDKey) targetAcctID := c.Param(IDKey)
if targetAcctID == "" { if targetAcctID == "" {
err := errors.New("no account id specified") err := errors.New("no account id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form := &apimodel.AccountFollowRequest{} form := &apimodel.AccountFollowRequest{}
if err := c.ShouldBind(form); err != nil { if err := c.ShouldBind(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form.ID = targetAcctID form.ID = targetAcctID
relationship, errWithCode := m.processor.AccountFollowCreate(c.Request.Context(), authed, form) relationship, errWithCode := m.processor.AccountFollowCreate(c.Request.Context(), authed, form)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -72,25 +72,25 @@
func (m *Module) AccountFollowersGETHandler(c *gin.Context) { func (m *Module) AccountFollowersGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetAcctID := c.Param(IDKey) targetAcctID := c.Param(IDKey)
if targetAcctID == "" { if targetAcctID == "" {
err := errors.New("no account id specified") err := errors.New("no account id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
followers, errWithCode := m.processor.AccountFollowersGet(c.Request.Context(), authed, targetAcctID) followers, errWithCode := m.processor.AccountFollowersGet(c.Request.Context(), authed, targetAcctID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -72,25 +72,25 @@
func (m *Module) AccountFollowingGETHandler(c *gin.Context) { func (m *Module) AccountFollowingGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetAcctID := c.Param(IDKey) targetAcctID := c.Param(IDKey)
if targetAcctID == "" { if targetAcctID == "" {
err := errors.New("no account id specified") err := errors.New("no account id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
following, errWithCode := m.processor.AccountFollowingGet(c.Request.Context(), authed, targetAcctID) following, errWithCode := m.processor.AccountFollowingGet(c.Request.Context(), authed, targetAcctID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -57,12 +57,12 @@
func (m *Module) AccountRelationshipsGETHandler(c *gin.Context) { func (m *Module) AccountRelationshipsGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -72,7 +72,7 @@ func (m *Module) AccountRelationshipsGETHandler(c *gin.Context) {
id := c.Query("id") id := c.Query("id")
if id == "" { if id == "" {
err = errors.New("no account id(s) specified in query") err = errors.New("no account id(s) specified in query")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetAccountIDs = append(targetAccountIDs, id) targetAccountIDs = append(targetAccountIDs, id)
@ -83,7 +83,7 @@ func (m *Module) AccountRelationshipsGETHandler(c *gin.Context) {
for _, targetAccountID := range targetAccountIDs { for _, targetAccountID := range targetAccountIDs {
r, errWithCode := m.processor.AccountRelationshipGet(c.Request.Context(), authed, targetAccountID) r, errWithCode := m.processor.AccountRelationshipGet(c.Request.Context(), authed, targetAccountID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
relationships = append(relationships, *r) relationships = append(relationships, *r)

View file

@ -133,19 +133,19 @@
func (m *Module) AccountStatusesGETHandler(c *gin.Context) { func (m *Module) AccountStatusesGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, false, false, false, false) authed, err := oauth.Authed(c, false, false, false, false)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetAcctID := c.Param(IDKey) targetAcctID := c.Param(IDKey)
if targetAcctID == "" { if targetAcctID == "" {
err := errors.New("no account id specified") err := errors.New("no account id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -155,7 +155,7 @@ func (m *Module) AccountStatusesGETHandler(c *gin.Context) {
i, err := strconv.ParseInt(limitString, 10, 32) i, err := strconv.ParseInt(limitString, 10, 32)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", LimitKey, err) err := fmt.Errorf("error parsing %s: %s", LimitKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
limit = int(i) limit = int(i)
@ -167,7 +167,7 @@ func (m *Module) AccountStatusesGETHandler(c *gin.Context) {
i, err := strconv.ParseBool(excludeRepliesString) i, err := strconv.ParseBool(excludeRepliesString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", ExcludeRepliesKey, err) err := fmt.Errorf("error parsing %s: %s", ExcludeRepliesKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
excludeReplies = i excludeReplies = i
@ -179,7 +179,7 @@ func (m *Module) AccountStatusesGETHandler(c *gin.Context) {
i, err := strconv.ParseBool(excludeReblogsString) i, err := strconv.ParseBool(excludeReblogsString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", ExcludeReblogsKey, err) err := fmt.Errorf("error parsing %s: %s", ExcludeReblogsKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
excludeReblogs = i excludeReblogs = i
@ -203,7 +203,7 @@ func (m *Module) AccountStatusesGETHandler(c *gin.Context) {
i, err := strconv.ParseBool(pinnedString) i, err := strconv.ParseBool(pinnedString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", PinnedKey, err) err := fmt.Errorf("error parsing %s: %s", PinnedKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
pinnedOnly = i pinnedOnly = i
@ -215,7 +215,7 @@ func (m *Module) AccountStatusesGETHandler(c *gin.Context) {
i, err := strconv.ParseBool(mediaOnlyString) i, err := strconv.ParseBool(mediaOnlyString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", OnlyMediaKey, err) err := fmt.Errorf("error parsing %s: %s", OnlyMediaKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
mediaOnly = i mediaOnly = i
@ -227,7 +227,7 @@ func (m *Module) AccountStatusesGETHandler(c *gin.Context) {
i, err := strconv.ParseBool(publicOnlyString) i, err := strconv.ParseBool(publicOnlyString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", OnlyPublicKey, err) err := fmt.Errorf("error parsing %s: %s", OnlyPublicKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
publicOnly = i publicOnly = i
@ -235,7 +235,7 @@ func (m *Module) AccountStatusesGETHandler(c *gin.Context) {
resp, errWithCode := m.processor.AccountStatusesGet(c.Request.Context(), authed, targetAcctID, limit, excludeReplies, excludeReblogs, maxID, minID, pinnedOnly, mediaOnly, publicOnly) resp, errWithCode := m.processor.AccountStatusesGet(c.Request.Context(), authed, targetAcctID, limit, excludeReplies, excludeReblogs, maxID, minID, pinnedOnly, mediaOnly, publicOnly)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -70,25 +70,25 @@
func (m *Module) AccountUnblockPOSTHandler(c *gin.Context) { func (m *Module) AccountUnblockPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetAcctID := c.Param(IDKey) targetAcctID := c.Param(IDKey)
if targetAcctID == "" { if targetAcctID == "" {
err := errors.New("no account id specified") err := errors.New("no account id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
relationship, errWithCode := m.processor.AccountBlockRemove(c.Request.Context(), authed, targetAcctID) relationship, errWithCode := m.processor.AccountBlockRemove(c.Request.Context(), authed, targetAcctID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -70,25 +70,25 @@
func (m *Module) AccountUnfollowPOSTHandler(c *gin.Context) { func (m *Module) AccountUnfollowPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetAcctID := c.Param(IDKey) targetAcctID := c.Param(IDKey)
if targetAcctID == "" { if targetAcctID == "" {
err := errors.New("no account id specified") err := errors.New("no account id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
relationship, errWithCode := m.processor.AccountFollowRemove(c.Request.Context(), authed, targetAcctID) relationship, errWithCode := m.processor.AccountFollowRemove(c.Request.Context(), authed, targetAcctID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -85,38 +85,38 @@
func (m *Module) AccountActionPOSTHandler(c *gin.Context) { func (m *Module) AccountActionPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !*authed.User.Admin { if !*authed.User.Admin {
err := fmt.Errorf("user %s not an admin", authed.User.ID) err := fmt.Errorf("user %s not an admin", authed.User.ID)
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form := &apimodel.AdminAccountActionRequest{} form := &apimodel.AdminAccountActionRequest{}
if err := c.ShouldBind(form); err != nil { if err := c.ShouldBind(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if form.Type == "" { if form.Type == "" {
err := errors.New("no type specified") err := errors.New("no type specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetAcctID := c.Param(IDKey) targetAcctID := c.Param(IDKey)
if targetAcctID == "" { if targetAcctID == "" {
err := errors.New("no account id specified") err := errors.New("no account id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form.TargetAccountID = targetAcctID form.TargetAccountID = targetAcctID
if errWithCode := m.processor.AdminAccountAction(c.Request.Context(), authed, form); errWithCode != nil { if errWithCode := m.processor.AdminAccountAction(c.Request.Context(), authed, form); errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -126,18 +126,18 @@
func (m *Module) DomainBlocksPOSTHandler(c *gin.Context) { func (m *Module) DomainBlocksPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !*authed.User.Admin { if !*authed.User.Admin {
err := fmt.Errorf("user %s not an admin", authed.User.ID) err := fmt.Errorf("user %s not an admin", authed.User.ID)
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -147,7 +147,7 @@ func (m *Module) DomainBlocksPOSTHandler(c *gin.Context) {
i, err := strconv.ParseBool(importString) i, err := strconv.ParseBool(importString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", ImportQueryKey, err) err := fmt.Errorf("error parsing %s: %s", ImportQueryKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
imp = i imp = i
@ -155,13 +155,13 @@ func (m *Module) DomainBlocksPOSTHandler(c *gin.Context) {
form := &apimodel.DomainBlockCreateRequest{} form := &apimodel.DomainBlockCreateRequest{}
if err := c.ShouldBind(form); err != nil { if err := c.ShouldBind(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if err := validateCreateDomainBlock(form, imp); err != nil { if err := validateCreateDomainBlock(form, imp); err != nil {
err := fmt.Errorf("error validating form: %s", err) err := fmt.Errorf("error validating form: %s", err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -169,7 +169,7 @@ func (m *Module) DomainBlocksPOSTHandler(c *gin.Context) {
// we're importing multiple blocks // we're importing multiple blocks
domainBlocks, errWithCode := m.processor.AdminDomainBlocksImport(c.Request.Context(), authed, form) domainBlocks, errWithCode := m.processor.AdminDomainBlocksImport(c.Request.Context(), authed, form)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
c.JSON(http.StatusOK, domainBlocks) c.JSON(http.StatusOK, domainBlocks)
@ -179,7 +179,7 @@ func (m *Module) DomainBlocksPOSTHandler(c *gin.Context) {
// we're just creating one block // we're just creating one block
domainBlock, errWithCode := m.processor.AdminDomainBlockCreate(c.Request.Context(), authed, form) domainBlock, errWithCode := m.processor.AdminDomainBlockCreate(c.Request.Context(), authed, form)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
c.JSON(http.StatusOK, domainBlock) c.JSON(http.StatusOK, domainBlock)

View file

@ -72,31 +72,31 @@
func (m *Module) DomainBlockDELETEHandler(c *gin.Context) { func (m *Module) DomainBlockDELETEHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !*authed.User.Admin { if !*authed.User.Admin {
err := fmt.Errorf("user %s not an admin", authed.User.ID) err := fmt.Errorf("user %s not an admin", authed.User.ID)
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
domainBlockID := c.Param(IDKey) domainBlockID := c.Param(IDKey)
if domainBlockID == "" { if domainBlockID == "" {
err := errors.New("no domain block id specified") err := errors.New("no domain block id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
domainBlock, errWithCode := m.processor.AdminDomainBlockDelete(c.Request.Context(), authed, domainBlockID) domainBlock, errWithCode := m.processor.AdminDomainBlockDelete(c.Request.Context(), authed, domainBlockID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -73,25 +73,25 @@
func (m *Module) DomainBlockGETHandler(c *gin.Context) { func (m *Module) DomainBlockGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !*authed.User.Admin { if !*authed.User.Admin {
err := fmt.Errorf("user %s not an admin", authed.User.ID) err := fmt.Errorf("user %s not an admin", authed.User.ID)
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
domainBlockID := c.Param(IDKey) domainBlockID := c.Param(IDKey)
if domainBlockID == "" { if domainBlockID == "" {
err := errors.New("no domain block id specified") err := errors.New("no domain block id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -101,7 +101,7 @@ func (m *Module) DomainBlockGETHandler(c *gin.Context) {
i, err := strconv.ParseBool(exportString) i, err := strconv.ParseBool(exportString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", ExportQueryKey, err) err := fmt.Errorf("error parsing %s: %s", ExportQueryKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
export = i export = i
@ -109,7 +109,7 @@ func (m *Module) DomainBlockGETHandler(c *gin.Context) {
domainBlock, errWithCode := m.processor.AdminDomainBlockGet(c.Request.Context(), authed, domainBlockID, export) domainBlock, errWithCode := m.processor.AdminDomainBlockGet(c.Request.Context(), authed, domainBlockID, export)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -78,18 +78,18 @@
func (m *Module) DomainBlocksGETHandler(c *gin.Context) { func (m *Module) DomainBlocksGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !*authed.User.Admin { if !*authed.User.Admin {
err := fmt.Errorf("user %s not an admin", authed.User.ID) err := fmt.Errorf("user %s not an admin", authed.User.ID)
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -99,7 +99,7 @@ func (m *Module) DomainBlocksGETHandler(c *gin.Context) {
i, err := strconv.ParseBool(exportString) i, err := strconv.ParseBool(exportString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", ExportQueryKey, err) err := fmt.Errorf("error parsing %s: %s", ExportQueryKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
export = i export = i
@ -107,7 +107,7 @@ func (m *Module) DomainBlocksGETHandler(c *gin.Context) {
domainBlocks, errWithCode := m.processor.AdminDomainBlocksGet(c.Request.Context(), authed, export) domainBlocks, errWithCode := m.processor.AdminDomainBlocksGet(c.Request.Context(), authed, export)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -69,24 +69,24 @@
func (m *Module) EmojiCategoriesGETHandler(c *gin.Context) { func (m *Module) EmojiCategoriesGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !*authed.User.Admin { if !*authed.User.Admin {
err := fmt.Errorf("user %s not an admin", authed.User.ID) err := fmt.Errorf("user %s not an admin", authed.User.ID)
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
categories, errWithCode := m.processor.AdminEmojiCategoriesGet(c.Request.Context()) categories, errWithCode := m.processor.AdminEmojiCategoriesGet(c.Request.Context())
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -100,35 +100,35 @@
func (m *Module) EmojiCreatePOSTHandler(c *gin.Context) { func (m *Module) EmojiCreatePOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !*authed.User.Admin { if !*authed.User.Admin {
err := fmt.Errorf("user %s not an admin", authed.User.ID) err := fmt.Errorf("user %s not an admin", authed.User.ID)
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form := &apimodel.EmojiCreateRequest{} form := &apimodel.EmojiCreateRequest{}
if err := c.ShouldBind(form); err != nil { if err := c.ShouldBind(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if err := validateCreateEmoji(form); err != nil { if err := validateCreateEmoji(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
apiEmoji, errWithCode := m.processor.AdminEmojiCreate(c.Request.Context(), authed, form) apiEmoji, errWithCode := m.processor.AdminEmojiCreate(c.Request.Context(), authed, form)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -78,31 +78,31 @@
func (m *Module) EmojiDELETEHandler(c *gin.Context) { func (m *Module) EmojiDELETEHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !*authed.User.Admin { if !*authed.User.Admin {
err := fmt.Errorf("user %s not an admin", authed.User.ID) err := fmt.Errorf("user %s not an admin", authed.User.ID)
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
emojiID := c.Param(IDKey) emojiID := c.Param(IDKey)
if emojiID == "" { if emojiID == "" {
err := errors.New("no emoji id specified") err := errors.New("no emoji id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
emoji, errWithCode := m.processor.AdminEmojiDelete(c.Request.Context(), authed, emojiID) emoji, errWithCode := m.processor.AdminEmojiDelete(c.Request.Context(), authed, emojiID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -68,31 +68,31 @@
func (m *Module) EmojiGETHandler(c *gin.Context) { func (m *Module) EmojiGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !*authed.User.Admin { if !*authed.User.Admin {
err := fmt.Errorf("user %s not an admin", authed.User.ID) err := fmt.Errorf("user %s not an admin", authed.User.ID)
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
emojiID := c.Param(IDKey) emojiID := c.Param(IDKey)
if emojiID == "" { if emojiID == "" {
err := errors.New("no emoji id specified") err := errors.New("no emoji id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
emoji, errWithCode := m.processor.AdminEmojiGet(c.Request.Context(), authed, emojiID) emoji, errWithCode := m.processor.AdminEmojiGet(c.Request.Context(), authed, emojiID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -125,18 +125,18 @@
func (m *Module) EmojisGETHandler(c *gin.Context) { func (m *Module) EmojisGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !*authed.User.Admin { if !*authed.User.Admin {
err := fmt.Errorf("user %s not an admin", authed.User.ID) err := fmt.Errorf("user %s not an admin", authed.User.ID)
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -149,7 +149,7 @@ func (m *Module) EmojisGETHandler(c *gin.Context) {
i, err := strconv.ParseInt(limitString, 10, 32) i, err := strconv.ParseInt(limitString, 10, 32)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", LimitKey, err) err := fmt.Errorf("error parsing %s: %s", LimitKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
limit = int(i) limit = int(i)
@ -177,7 +177,7 @@ func (m *Module) EmojisGETHandler(c *gin.Context) {
shortcode = strings.Trim(filter[10:], ":") // remove any errant ":" shortcode = strings.Trim(filter[10:], ":") // remove any errant ":"
default: default:
err := fmt.Errorf("filter %s not recognized; accepted values are 'domain:[domain]', 'disabled', 'enabled', 'shortcode:[shortcode]'", filter) err := fmt.Errorf("filter %s not recognized; accepted values are 'domain:[domain]', 'disabled', 'enabled', 'shortcode:[shortcode]'", filter)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
} }
@ -200,7 +200,7 @@ func (m *Module) EmojisGETHandler(c *gin.Context) {
resp, errWithCode := m.processor.AdminEmojisGet(c.Request.Context(), authed, domain, includeDisabled, includeEnabled, shortcode, maxShortcodeDomain, minShortcodeDomain, limit) resp, errWithCode := m.processor.AdminEmojisGet(c.Request.Context(), authed, domain, includeDisabled, includeEnabled, shortcode, maxShortcodeDomain, minShortcodeDomain, limit)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -123,42 +123,42 @@
func (m *Module) EmojiPATCHHandler(c *gin.Context) { func (m *Module) EmojiPATCHHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !*authed.User.Admin { if !*authed.User.Admin {
err := fmt.Errorf("user %s not an admin", authed.User.ID) err := fmt.Errorf("user %s not an admin", authed.User.ID)
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
emojiID := c.Param(IDKey) emojiID := c.Param(IDKey)
if emojiID == "" { if emojiID == "" {
err := errors.New("no emoji id specified") err := errors.New("no emoji id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form := &apimodel.EmojiUpdateRequest{} form := &apimodel.EmojiUpdateRequest{}
if err := c.ShouldBind(form); err != nil { if err := c.ShouldBind(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if err := validateUpdateEmoji(form); err != nil { if err := validateUpdateEmoji(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
emoji, errWithCode := m.processor.AdminEmojiUpdate(c.Request.Context(), emojiID, form) emoji, errWithCode := m.processor.AdminEmojiUpdate(c.Request.Context(), emojiID, form)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -71,19 +71,19 @@
func (m *Module) MediaCleanupPOSTHandler(c *gin.Context) { func (m *Module) MediaCleanupPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !*authed.User.Admin { if !*authed.User.Admin {
err := fmt.Errorf("user %s not an admin", authed.User.ID) err := fmt.Errorf("user %s not an admin", authed.User.ID)
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form := &apimodel.MediaCleanupRequest{} form := &apimodel.MediaCleanupRequest{}
if err := c.ShouldBind(form); err != nil { if err := c.ShouldBind(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -98,7 +98,7 @@ func (m *Module) MediaCleanupPOSTHandler(c *gin.Context) {
} }
if errWithCode := m.processor.AdminMediaPrune(c.Request.Context(), remoteCacheDays); errWithCode != nil { if errWithCode := m.processor.AdminMediaPrune(c.Request.Context(), remoteCacheDays); errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -74,18 +74,18 @@
func (m *Module) MediaRefetchPOSTHandler(c *gin.Context) { func (m *Module) MediaRefetchPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !*authed.User.Admin { if !*authed.User.Admin {
err := fmt.Errorf("user %s not an admin", authed.User.ID) err := fmt.Errorf("user %s not an admin", authed.User.ID)
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if errWithCode := m.processor.AdminMediaRefetch(c.Request.Context(), authed, c.Query(DomainQueryKey)); errWithCode != nil { if errWithCode := m.processor.AdminMediaRefetch(c.Request.Context(), authed, c.Query(DomainQueryKey)); errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -71,31 +71,31 @@
func (m *Module) ReportGETHandler(c *gin.Context) { func (m *Module) ReportGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !*authed.User.Admin { if !*authed.User.Admin {
err := fmt.Errorf("user %s not an admin", authed.User.ID) err := fmt.Errorf("user %s not an admin", authed.User.ID)
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
reportID := c.Param(IDKey) reportID := c.Param(IDKey)
if reportID == "" { if reportID == "" {
err := errors.New("no report id specified") err := errors.New("no report id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
report, errWithCode := m.processor.AdminReportGet(c.Request.Context(), authed, reportID) report, errWithCode := m.processor.AdminReportGet(c.Request.Context(), authed, reportID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -87,37 +87,37 @@
func (m *Module) ReportResolvePOSTHandler(c *gin.Context) { func (m *Module) ReportResolvePOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !*authed.User.Admin { if !*authed.User.Admin {
err := fmt.Errorf("user %s not an admin", authed.User.ID) err := fmt.Errorf("user %s not an admin", authed.User.ID)
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
reportID := c.Param(IDKey) reportID := c.Param(IDKey)
if reportID == "" { if reportID == "" {
err := errors.New("no report id specified") err := errors.New("no report id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form := &apimodel.AdminReportResolveRequest{} form := &apimodel.AdminReportResolveRequest{}
if err := c.ShouldBind(form); err != nil { if err := c.ShouldBind(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
report, errWithCode := m.processor.AdminReportResolve(c.Request.Context(), authed, reportID, form.ActionTakenComment) report, errWithCode := m.processor.AdminReportResolve(c.Request.Context(), authed, reportID, form.ActionTakenComment)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -127,18 +127,18 @@
func (m *Module) ReportsGETHandler(c *gin.Context) { func (m *Module) ReportsGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !*authed.User.Admin { if !*authed.User.Admin {
err := fmt.Errorf("user %s not an admin", authed.User.ID) err := fmt.Errorf("user %s not an admin", authed.User.ID)
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -147,7 +147,7 @@ func (m *Module) ReportsGETHandler(c *gin.Context) {
i, err := strconv.ParseBool(resolvedString) i, err := strconv.ParseBool(resolvedString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", ResolvedKey, err) err := fmt.Errorf("error parsing %s: %s", ResolvedKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
resolved = &i resolved = &i
@ -158,7 +158,7 @@ func (m *Module) ReportsGETHandler(c *gin.Context) {
i, err := strconv.Atoi(limitString) i, err := strconv.Atoi(limitString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", LimitKey, err) err := fmt.Errorf("error parsing %s: %s", LimitKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -173,7 +173,7 @@ func (m *Module) ReportsGETHandler(c *gin.Context) {
resp, errWithCode := m.processor.AdminReportsGet(c.Request.Context(), authed, resolved, c.Query(AccountIDKey), c.Query(TargetAccountIDKey), c.Query(MaxIDKey), c.Query(SinceIDKey), c.Query(MinIDKey), limit) resp, errWithCode := m.processor.AdminReportsGet(c.Request.Context(), authed, resolved, c.Query(AccountIDKey), c.Query(TargetAccountIDKey), c.Query(MaxIDKey), c.Query(SinceIDKey), c.Query(MinIDKey), limit)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -77,48 +77,48 @@
func (m *Module) AppsPOSTHandler(c *gin.Context) { func (m *Module) AppsPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, false, false, false, false) authed, err := oauth.Authed(c, false, false, false, false)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form := &apimodel.ApplicationCreateRequest{} form := &apimodel.ApplicationCreateRequest{}
if err := c.ShouldBind(form); err != nil { if err := c.ShouldBind(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if len([]rune(form.ClientName)) > formFieldLen { if len([]rune(form.ClientName)) > formFieldLen {
err := fmt.Errorf("client_name must be less than %d characters", formFieldLen) err := fmt.Errorf("client_name must be less than %d characters", formFieldLen)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if len([]rune(form.RedirectURIs)) > formRedirectLen { if len([]rune(form.RedirectURIs)) > formRedirectLen {
err := fmt.Errorf("redirect_uris must be less than %d characters", formRedirectLen) err := fmt.Errorf("redirect_uris must be less than %d characters", formRedirectLen)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if len([]rune(form.Scopes)) > formFieldLen { if len([]rune(form.Scopes)) > formFieldLen {
err := fmt.Errorf("scopes must be less than %d characters", formFieldLen) err := fmt.Errorf("scopes must be less than %d characters", formFieldLen)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if len([]rune(form.Website)) > formFieldLen { if len([]rune(form.Website)) > formFieldLen {
err := fmt.Errorf("website must be less than %d characters", formFieldLen) err := fmt.Errorf("website must be less than %d characters", formFieldLen)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
apiApp, errWithCode := m.processor.AppCreate(c.Request.Context(), authed, form) apiApp, errWithCode := m.processor.AppCreate(c.Request.Context(), authed, form)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -96,12 +96,12 @@
func (m *Module) BlocksGETHandler(c *gin.Context) { func (m *Module) BlocksGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -123,7 +123,7 @@ func (m *Module) BlocksGETHandler(c *gin.Context) {
i, err := strconv.ParseInt(limitString, 10, 32) i, err := strconv.ParseInt(limitString, 10, 32)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", LimitKey, err) err := fmt.Errorf("error parsing %s: %s", LimitKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
limit = int(i) limit = int(i)
@ -131,7 +131,7 @@ func (m *Module) BlocksGETHandler(c *gin.Context) {
resp, errWithCode := m.processor.BlocksGet(c.Request.Context(), authed, maxID, sinceID, limit) resp, errWithCode := m.processor.BlocksGet(c.Request.Context(), authed, maxID, sinceID, limit)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -56,12 +56,12 @@
func (m *Module) BookmarksGETHandler(c *gin.Context) { func (m *Module) BookmarksGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -71,7 +71,7 @@ func (m *Module) BookmarksGETHandler(c *gin.Context) {
i, err := strconv.ParseInt(limitString, 10, 64) i, err := strconv.ParseInt(limitString, 10, 64)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", LimitKey, err) err := fmt.Errorf("error parsing %s: %s", LimitKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
limit = int(i) limit = int(i)
@ -91,12 +91,12 @@ func (m *Module) BookmarksGETHandler(c *gin.Context) {
resp, errWithCode := m.processor.BookmarksGet(c.Request.Context(), authed, maxID, minID, limit) resp, errWithCode := m.processor.BookmarksGet(c.Request.Context(), authed, maxID, minID, limit)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -57,18 +57,18 @@
// description: internal server error // description: internal server error
func (m *Module) CustomEmojisGETHandler(c *gin.Context) { func (m *Module) CustomEmojisGETHandler(c *gin.Context) {
if _, err := oauth.Authed(c, true, true, true, true); err != nil { if _, err := oauth.Authed(c, true, true, true, true); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
emojis, errWithCode := m.processor.CustomEmojisGet(c) emojis, errWithCode := m.processor.CustomEmojisGet(c)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -78,12 +78,12 @@
func (m *Module) FavouritesGETHandler(c *gin.Context) { func (m *Module) FavouritesGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -105,7 +105,7 @@ func (m *Module) FavouritesGETHandler(c *gin.Context) {
i, err := strconv.ParseInt(limitString, 10, 32) i, err := strconv.ParseInt(limitString, 10, 32)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", LimitKey, err) err := fmt.Errorf("error parsing %s: %s", LimitKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
limit = int(i) limit = int(i)
@ -113,7 +113,7 @@ func (m *Module) FavouritesGETHandler(c *gin.Context) {
resp, errWithCode := m.processor.FavedTimelineGet(c.Request.Context(), authed, maxID, minID, limit) resp, errWithCode := m.processor.FavedTimelineGet(c.Request.Context(), authed, maxID, minID, limit)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -12,12 +12,12 @@
// FiltersGETHandler returns a list of filters set by/for the authed account // FiltersGETHandler returns a list of filters set by/for the authed account
func (m *Module) FiltersGETHandler(c *gin.Context) { func (m *Module) FiltersGETHandler(c *gin.Context) {
if _, err := oauth.Authed(c, true, true, true, true); err != nil { if _, err := oauth.Authed(c, true, true, true, true); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }

View file

@ -72,25 +72,25 @@
func (m *Module) FollowRequestAuthorizePOSTHandler(c *gin.Context) { func (m *Module) FollowRequestAuthorizePOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
originAccountID := c.Param(IDKey) originAccountID := c.Param(IDKey)
if originAccountID == "" { if originAccountID == "" {
err := errors.New("no account id specified") err := errors.New("no account id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
relationship, errWithCode := m.processor.FollowRequestAccept(c.Request.Context(), authed, originAccountID) relationship, errWithCode := m.processor.FollowRequestAccept(c.Request.Context(), authed, originAccountID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -74,18 +74,18 @@
func (m *Module) FollowRequestGETHandler(c *gin.Context) { func (m *Module) FollowRequestGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
accts, errWithCode := m.processor.FollowRequestsGet(c.Request.Context(), authed) accts, errWithCode := m.processor.FollowRequestsGet(c.Request.Context(), authed)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -70,25 +70,25 @@
func (m *Module) FollowRequestRejectPOSTHandler(c *gin.Context) { func (m *Module) FollowRequestRejectPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
originAccountID := c.Param(IDKey) originAccountID := c.Param(IDKey)
if originAccountID == "" { if originAccountID == "" {
err := errors.New("no account id specified") err := errors.New("no account id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
relationship, errWithCode := m.processor.FollowRequestReject(c.Request.Context(), authed, originAccountID) relationship, errWithCode := m.processor.FollowRequestReject(c.Request.Context(), authed, originAccountID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -26,12 +26,10 @@
) )
const ( const (
// InstanceInformationPath is for serving instance info requests, minus the 'api' prefix. InstanceInformationPathV1 = "/v1/instance"
InstanceInformationPath = "/v1/instance" InstanceInformationPathV2 = "/v2/instance"
// InstancePeersPath is for serving instance peers requests. InstancePeersPath = InstanceInformationPathV1 + "/peers"
InstancePeersPath = InstanceInformationPath + "/peers" PeersFilterKey = "filter" // PeersFilterKey is used to provide filters to /api/v1/instance/peers
// PeersFilterKey is used to provide filters to /api/v1/instance/peers
PeersFilterKey = "filter"
) )
type Module struct { type Module struct {
@ -45,7 +43,9 @@ func New(processor processing.Processor) *Module {
} }
func (m *Module) Route(attachHandler func(method string, path string, f ...gin.HandlerFunc) gin.IRoutes) { func (m *Module) Route(attachHandler func(method string, path string, f ...gin.HandlerFunc) gin.IRoutes) {
attachHandler(http.MethodGet, InstanceInformationPath, m.InstanceInformationGETHandler) attachHandler(http.MethodGet, InstanceInformationPathV1, m.InstanceInformationGETHandlerV1)
attachHandler(http.MethodPatch, InstanceInformationPath, m.InstanceUpdatePATCHHandler) attachHandler(http.MethodGet, InstanceInformationPathV2, m.InstanceInformationGETHandlerV2)
attachHandler(http.MethodPatch, InstanceInformationPathV1, m.InstanceUpdatePATCHHandler)
attachHandler(http.MethodGet, InstancePeersPath, m.InstancePeersGETHandler) attachHandler(http.MethodGet, InstancePeersPath, m.InstancePeersGETHandler)
} }

View file

@ -22,13 +22,12 @@
"net/http" "net/http"
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util" apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
// InstanceInformationGETHandler swagger:operation GET /api/v1/instance instanceGet // InstanceInformationV1GETHandlerV1 swagger:operation GET /api/v1/instance instanceGetV1
// //
// View instance information. // View instance information.
// //
@ -43,20 +42,55 @@
// '200': // '200':
// description: "Instance information." // description: "Instance information."
// schema: // schema:
// "$ref": "#/definitions/instance" // "$ref": "#/definitions/instanceV1"
// '406': // '406':
// description: not acceptable // description: not acceptable
// '500': // '500':
// description: internal error // description: internal error
func (m *Module) InstanceInformationGETHandler(c *gin.Context) { func (m *Module) InstanceInformationGETHandlerV1(c *gin.Context) {
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
instance, errWithCode := m.processor.InstanceGet(c.Request.Context(), config.GetHost()) instance, errWithCode := m.processor.InstanceGetV1(c.Request.Context())
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return
}
c.JSON(http.StatusOK, instance)
}
// InstanceInformationGETHandlerV2 swagger:operation GET /api/v2/instance instanceGetV2
//
// View instance information.
//
// ---
// tags:
// - instance
//
// produces:
// - application/json
//
// responses:
// '200':
// description: "Instance information."
// schema:
// "$ref": "#/definitions/instanceV2"
// '406':
// description: not acceptable
// '500':
// description: internal error
func (m *Module) InstanceInformationGETHandlerV2(c *gin.Context) {
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return
}
instance, errWithCode := m.processor.InstanceGetV2(c.Request.Context())
if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -130,35 +130,35 @@
func (m *Module) InstanceUpdatePATCHHandler(c *gin.Context) { func (m *Module) InstanceUpdatePATCHHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !*authed.User.Admin { if !*authed.User.Admin {
err := errors.New("user is not an admin so cannot update instance settings") err := errors.New("user is not an admin so cannot update instance settings")
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form := &apimodel.InstanceSettingsUpdateRequest{} form := &apimodel.InstanceSettingsUpdateRequest{}
if err := c.ShouldBind(&form); err != nil { if err := c.ShouldBind(&form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if err := validateInstanceUpdate(form); err != nil { if err := validateInstanceUpdate(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
i, errWithCode := m.processor.InstancePatch(c.Request.Context(), form) i, errWithCode := m.processor.InstancePatch(c.Request.Context(), form)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -52,7 +52,7 @@ func (suite *InstancePatchTestSuite) TestInstancePatch1() {
// set up the request // set up the request
recorder := httptest.NewRecorder() recorder := httptest.NewRecorder()
ctx := suite.newContext(recorder, http.MethodPatch, instance.InstanceInformationPath, bodyBytes, w.FormDataContentType(), true) ctx := suite.newContext(recorder, http.MethodPatch, instance.InstanceInformationPathV1, bodyBytes, w.FormDataContentType(), true)
// call the handler // call the handler
suite.instanceModule.InstanceUpdatePATCHHandler(ctx) suite.instanceModule.InstanceUpdatePATCHHandler(ctx)
@ -106,7 +106,8 @@ func (suite *InstancePatchTestSuite) TestInstancePatch1() {
"max_expiration": 2629746 "max_expiration": 2629746
}, },
"accounts": { "accounts": {
"allow_custom_css": true "allow_custom_css": true,
"max_featured_tags": 10
}, },
"emojis": { "emojis": {
"emoji_size_limit": 51200 "emoji_size_limit": 51200
@ -161,7 +162,7 @@ func (suite *InstancePatchTestSuite) TestInstancePatch2() {
// set up the request // set up the request
recorder := httptest.NewRecorder() recorder := httptest.NewRecorder()
ctx := suite.newContext(recorder, http.MethodPatch, instance.InstanceInformationPath, bodyBytes, w.FormDataContentType(), true) ctx := suite.newContext(recorder, http.MethodPatch, instance.InstanceInformationPathV1, bodyBytes, w.FormDataContentType(), true)
// call the handler // call the handler
suite.instanceModule.InstanceUpdatePATCHHandler(ctx) suite.instanceModule.InstanceUpdatePATCHHandler(ctx)
@ -215,7 +216,8 @@ func (suite *InstancePatchTestSuite) TestInstancePatch2() {
"max_expiration": 2629746 "max_expiration": 2629746
}, },
"accounts": { "accounts": {
"allow_custom_css": true "allow_custom_css": true,
"max_featured_tags": 10
}, },
"emojis": { "emojis": {
"emoji_size_limit": 51200 "emoji_size_limit": 51200
@ -270,7 +272,7 @@ func (suite *InstancePatchTestSuite) TestInstancePatch3() {
// set up the request // set up the request
recorder := httptest.NewRecorder() recorder := httptest.NewRecorder()
ctx := suite.newContext(recorder, http.MethodPatch, instance.InstanceInformationPath, bodyBytes, w.FormDataContentType(), true) ctx := suite.newContext(recorder, http.MethodPatch, instance.InstanceInformationPathV1, bodyBytes, w.FormDataContentType(), true)
// call the handler // call the handler
suite.instanceModule.InstanceUpdatePATCHHandler(ctx) suite.instanceModule.InstanceUpdatePATCHHandler(ctx)
@ -324,7 +326,8 @@ func (suite *InstancePatchTestSuite) TestInstancePatch3() {
"max_expiration": 2629746 "max_expiration": 2629746
}, },
"accounts": { "accounts": {
"allow_custom_css": true "allow_custom_css": true,
"max_featured_tags": 10
}, },
"emojis": { "emojis": {
"emoji_size_limit": 51200 "emoji_size_limit": 51200
@ -377,7 +380,7 @@ func (suite *InstancePatchTestSuite) TestInstancePatch4() {
// set up the request // set up the request
recorder := httptest.NewRecorder() recorder := httptest.NewRecorder()
ctx := suite.newContext(recorder, http.MethodPatch, instance.InstanceInformationPath, bodyBytes, w.FormDataContentType(), true) ctx := suite.newContext(recorder, http.MethodPatch, instance.InstanceInformationPathV1, bodyBytes, w.FormDataContentType(), true)
// call the handler // call the handler
suite.instanceModule.InstanceUpdatePATCHHandler(ctx) suite.instanceModule.InstanceUpdatePATCHHandler(ctx)
@ -406,7 +409,7 @@ func (suite *InstancePatchTestSuite) TestInstancePatch5() {
// set up the request // set up the request
recorder := httptest.NewRecorder() recorder := httptest.NewRecorder()
ctx := suite.newContext(recorder, http.MethodPatch, instance.InstanceInformationPath, bodyBytes, w.FormDataContentType(), true) ctx := suite.newContext(recorder, http.MethodPatch, instance.InstanceInformationPathV1, bodyBytes, w.FormDataContentType(), true)
ctx.Set(oauth.SessionAuthorizedAccount, suite.testAccounts["local_account_1"]) ctx.Set(oauth.SessionAuthorizedAccount, suite.testAccounts["local_account_1"])
ctx.Set(oauth.SessionAuthorizedToken, oauth.DBTokenToToken(suite.testTokens["local_account_1"])) ctx.Set(oauth.SessionAuthorizedToken, oauth.DBTokenToToken(suite.testTokens["local_account_1"]))
@ -440,7 +443,7 @@ func (suite *InstancePatchTestSuite) TestInstancePatch6() {
// set up the request // set up the request
recorder := httptest.NewRecorder() recorder := httptest.NewRecorder()
ctx := suite.newContext(recorder, http.MethodPatch, instance.InstanceInformationPath, bodyBytes, w.FormDataContentType(), true) ctx := suite.newContext(recorder, http.MethodPatch, instance.InstanceInformationPathV1, bodyBytes, w.FormDataContentType(), true)
// call the handler // call the handler
suite.instanceModule.InstanceUpdatePATCHHandler(ctx) suite.instanceModule.InstanceUpdatePATCHHandler(ctx)
@ -494,7 +497,8 @@ func (suite *InstancePatchTestSuite) TestInstancePatch6() {
"max_expiration": 2629746 "max_expiration": 2629746
}, },
"accounts": { "accounts": {
"allow_custom_css": true "allow_custom_css": true,
"max_featured_tags": 10
}, },
"emojis": { "emojis": {
"emoji_size_limit": 51200 "emoji_size_limit": 51200
@ -549,7 +553,7 @@ func (suite *InstancePatchTestSuite) TestInstancePatch7() {
// set up the request // set up the request
recorder := httptest.NewRecorder() recorder := httptest.NewRecorder()
ctx := suite.newContext(recorder, http.MethodPatch, instance.InstanceInformationPath, bodyBytes, w.FormDataContentType(), true) ctx := suite.newContext(recorder, http.MethodPatch, instance.InstanceInformationPathV1, bodyBytes, w.FormDataContentType(), true)
// call the handler // call the handler
suite.instanceModule.InstanceUpdatePATCHHandler(ctx) suite.instanceModule.InstanceUpdatePATCHHandler(ctx)
@ -578,7 +582,7 @@ func (suite *InstancePatchTestSuite) TestInstancePatch8() {
// set up the request // set up the request
recorder := httptest.NewRecorder() recorder := httptest.NewRecorder()
ctx := suite.newContext(recorder, http.MethodPatch, instance.InstanceInformationPath, bodyBytes, w.FormDataContentType(), true) ctx := suite.newContext(recorder, http.MethodPatch, instance.InstanceInformationPathV1, bodyBytes, w.FormDataContentType(), true)
// call the handler // call the handler
suite.instanceModule.InstanceUpdatePATCHHandler(ctx) suite.instanceModule.InstanceUpdatePATCHHandler(ctx)
@ -636,7 +640,8 @@ func (suite *InstancePatchTestSuite) TestInstancePatch8() {
"max_expiration": 2629746 "max_expiration": 2629746
}, },
"accounts": { "accounts": {
"allow_custom_css": true "allow_custom_css": true,
"max_featured_tags": 10
}, },
"emojis": { "emojis": {
"emoji_size_limit": 51200 "emoji_size_limit": 51200
@ -678,6 +683,24 @@ func (suite *InstancePatchTestSuite) TestInstancePatch8() {
}, },
"max_toot_chars": 5000 "max_toot_chars": 5000
}`, dst.String()) }`, dst.String())
// extra bonus: check the v2 model thumbnail after the patch
instanceV2, err := suite.processor.InstanceGetV2(ctx)
if err != nil {
suite.FailNow(err.Error())
}
instanceV2ThumbnailJson, err := json.MarshalIndent(instanceV2.Thumbnail, "", " ")
if err != nil {
suite.FailNow(err.Error())
}
suite.Equal(`{
"url": "http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/attachment/original/`+instanceAccount.AvatarMediaAttachment.ID+`.gif",`+`
"thumbnail_type": "image/gif",
"thumbnail_description": "A bouncing little green peglin.",
"blurhash": "LG9t;qRS4YtO.4WDRlt5IXoxtPj["
}`, string(instanceV2ThumbnailJson))
} }
func TestInstancePatchTestSuite(t *testing.T) { func TestInstancePatchTestSuite(t *testing.T) {

View file

@ -102,14 +102,14 @@
func (m *Module) InstancePeersGETHandler(c *gin.Context) { func (m *Module) InstancePeersGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, false, false, false, false) authed, err := oauth.Authed(c, false, false, false, false)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
var isUnauthenticated = authed.Account == nil || authed.User == nil var isUnauthenticated = authed.Account == nil || authed.User == nil
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -127,7 +127,7 @@ func (m *Module) InstancePeersGETHandler(c *gin.Context) {
includeOpen = true includeOpen = true
default: default:
err := fmt.Errorf("filter %s not recognized; accepted values are 'open', 'suspended'", trimmed) err := fmt.Errorf("filter %s not recognized; accepted values are 'open', 'suspended'", trimmed)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
} }
@ -141,19 +141,19 @@ func (m *Module) InstancePeersGETHandler(c *gin.Context) {
if includeOpen && !config.GetInstanceExposePeers() && isUnauthenticated { if includeOpen && !config.GetInstanceExposePeers() && isUnauthenticated {
err := fmt.Errorf("peers open query requires an authenticated account/user") err := fmt.Errorf("peers open query requires an authenticated account/user")
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if includeSuspended && !config.GetInstanceExposeSuspended() && isUnauthenticated { if includeSuspended && !config.GetInstanceExposeSuspended() && isUnauthenticated {
err := fmt.Errorf("peers suspended query requires an authenticated account/user") err := fmt.Errorf("peers suspended query requires an authenticated account/user")
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
data, errWithCode := m.processor.InstancePeersGet(c.Request.Context(), includeSuspended, includeOpen, flat) data, errWithCode := m.processor.InstancePeersGet(c.Request.Context(), includeSuspended, includeOpen, flat)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -30,12 +30,12 @@
// ListsGETHandler returns a list of lists created by/for the authed account // ListsGETHandler returns a list of lists created by/for the authed account
func (m *Module) ListsGETHandler(c *gin.Context) { func (m *Module) ListsGETHandler(c *gin.Context) {
if _, err := oauth.Authed(c, true, true, true, true); err != nil { if _, err := oauth.Authed(c, true, true, true, true); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }

View file

@ -97,35 +97,35 @@ func (m *Module) MediaCreatePOSTHandler(c *gin.Context) {
apiVersion := c.Param(APIVersionKey) apiVersion := c.Param(APIVersionKey)
if apiVersion != APIv1 && apiVersion != APIv2 { if apiVersion != APIv1 && apiVersion != APIv2 {
err := errors.New("api version must be one of v1 or v2 for this path") err := errors.New("api version must be one of v1 or v2 for this path")
apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form := &apimodel.AttachmentRequest{} form := &apimodel.AttachmentRequest{}
if err := c.ShouldBind(&form); err != nil { if err := c.ShouldBind(&form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if err := validateCreateMedia(form); err != nil { if err := validateCreateMedia(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
apiAttachment, errWithCode := m.processor.MediaCreate(c.Request.Context(), authed, form) apiAttachment, errWithCode := m.processor.MediaCreate(c.Request.Context(), authed, form)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -69,31 +69,31 @@
func (m *Module) MediaGETHandler(c *gin.Context) { func (m *Module) MediaGETHandler(c *gin.Context) {
if apiVersion := c.Param(APIVersionKey); apiVersion != APIv1 { if apiVersion := c.Param(APIVersionKey); apiVersion != APIv1 {
err := errors.New("api version must be one v1 for this path") err := errors.New("api version must be one v1 for this path")
apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
attachmentID := c.Param(IDKey) attachmentID := c.Param(IDKey)
if attachmentID == "" { if attachmentID == "" {
err := errors.New("no attachment id specified") err := errors.New("no attachment id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
attachment, errWithCode := m.processor.MediaGet(c.Request.Context(), authed, attachmentID) attachment, errWithCode := m.processor.MediaGet(c.Request.Context(), authed, attachmentID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -101,42 +101,42 @@
func (m *Module) MediaPUTHandler(c *gin.Context) { func (m *Module) MediaPUTHandler(c *gin.Context) {
if apiVersion := c.Param(APIVersionKey); apiVersion != APIv1 { if apiVersion := c.Param(APIVersionKey); apiVersion != APIv1 {
err := errors.New("api version must be one v1 for this path") err := errors.New("api version must be one v1 for this path")
apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
attachmentID := c.Param(IDKey) attachmentID := c.Param(IDKey)
if attachmentID == "" { if attachmentID == "" {
err := errors.New("no attachment id specified") err := errors.New("no attachment id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form := &apimodel.AttachmentUpdateRequest{} form := &apimodel.AttachmentUpdateRequest{}
if err := c.ShouldBind(form); err != nil { if err := c.ShouldBind(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if err := validateUpdateMedia(form); err != nil { if err := validateUpdateMedia(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
attachment, errWithCode := m.processor.MediaUpdate(c.Request.Context(), authed, attachmentID, form) attachment, errWithCode := m.processor.MediaUpdate(c.Request.Context(), authed, attachmentID, form)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -61,18 +61,18 @@
func (m *Module) NotificationsClearPOSTHandler(c *gin.Context) { func (m *Module) NotificationsClearPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
errWithCode := m.processor.NotificationsClear(c.Request.Context(), authed) errWithCode := m.processor.NotificationsClear(c.Request.Context(), authed)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -111,12 +111,12 @@
func (m *Module) NotificationsGETHandler(c *gin.Context) { func (m *Module) NotificationsGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -126,7 +126,7 @@ func (m *Module) NotificationsGETHandler(c *gin.Context) {
i, err := strconv.ParseInt(limitString, 10, 32) i, err := strconv.ParseInt(limitString, 10, 32)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", LimitKey, err) err := fmt.Errorf("error parsing %s: %s", LimitKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
limit = int(i) limit = int(i)
@ -148,7 +148,7 @@ func (m *Module) NotificationsGETHandler(c *gin.Context) {
resp, errWithCode := m.processor.NotificationsGet(c.Request.Context(), authed, excludeTypes, limit, maxID, sinceID) resp, errWithCode := m.processor.NotificationsGet(c.Request.Context(), authed, excludeTypes, limit, maxID, sinceID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -69,42 +69,42 @@
func (m *Module) ReportPOSTHandler(c *gin.Context) { func (m *Module) ReportPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form := &apimodel.ReportCreateRequest{} form := &apimodel.ReportCreateRequest{}
if err := c.ShouldBind(form); err != nil { if err := c.ShouldBind(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if form.AccountID == "" { if form.AccountID == "" {
err = errors.New("account_id must be set") err = errors.New("account_id must be set")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if !regexes.ULID.MatchString(form.AccountID) { if !regexes.ULID.MatchString(form.AccountID) {
err = errors.New("account_id was not valid") err = errors.New("account_id was not valid")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if length := len([]rune(form.Comment)); length > 1000 { if length := len([]rune(form.Comment)); length > 1000 {
err = fmt.Errorf("comment length must be no more than 1000 chars, provided comment was %d chars", length) err = fmt.Errorf("comment length must be no more than 1000 chars, provided comment was %d chars", length)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
apiReport, errWithCode := m.processor.ReportCreate(c.Request.Context(), authed, form) apiReport, errWithCode := m.processor.ReportCreate(c.Request.Context(), authed, form)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -69,25 +69,25 @@
func (m *Module) ReportGETHandler(c *gin.Context) { func (m *Module) ReportGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetReportID := c.Param(IDKey) targetReportID := c.Param(IDKey)
if targetReportID == "" { if targetReportID == "" {
err := errors.New("no report id specified") err := errors.New("no report id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
report, errWithCode := m.processor.ReportGet(c.Request.Context(), authed, targetReportID) report, errWithCode := m.processor.ReportGet(c.Request.Context(), authed, targetReportID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -122,12 +122,12 @@
func (m *Module) ReportsGETHandler(c *gin.Context) { func (m *Module) ReportsGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -136,7 +136,7 @@ func (m *Module) ReportsGETHandler(c *gin.Context) {
i, err := strconv.ParseBool(resolvedString) i, err := strconv.ParseBool(resolvedString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", ResolvedKey, err) err := fmt.Errorf("error parsing %s: %s", ResolvedKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
resolved = &i resolved = &i
@ -147,7 +147,7 @@ func (m *Module) ReportsGETHandler(c *gin.Context) {
i, err := strconv.Atoi(limitString) i, err := strconv.Atoi(limitString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", LimitKey, err) err := fmt.Errorf("error parsing %s: %s", LimitKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -162,7 +162,7 @@ func (m *Module) ReportsGETHandler(c *gin.Context) {
resp, errWithCode := m.processor.ReportsGet(c.Request.Context(), authed, resolved, c.Query(TargetAccountIDKey), c.Query(MaxIDKey), c.Query(SinceIDKey), c.Query(MinIDKey), limit) resp, errWithCode := m.processor.ReportsGet(c.Request.Context(), authed, resolved, c.Query(TargetAccountIDKey), c.Query(MaxIDKey), c.Query(SinceIDKey), c.Query(MinIDKey), limit)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -66,12 +66,12 @@
func (m *Module) SearchGETHandler(c *gin.Context) { func (m *Module) SearchGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -82,7 +82,7 @@ func (m *Module) SearchGETHandler(c *gin.Context) {
excludeUnreviewed, err = strconv.ParseBool(excludeUnreviewedString) excludeUnreviewed, err = strconv.ParseBool(excludeUnreviewedString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", ExcludeUnreviewedKey, err) err := fmt.Errorf("error parsing %s: %s", ExcludeUnreviewedKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
} }
@ -90,7 +90,7 @@ func (m *Module) SearchGETHandler(c *gin.Context) {
query := c.Query(QueryKey) query := c.Query(QueryKey)
if query == "" { if query == "" {
err := errors.New("query parameter q was empty") err := errors.New("query parameter q was empty")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -101,7 +101,7 @@ func (m *Module) SearchGETHandler(c *gin.Context) {
resolve, err = strconv.ParseBool(resolveString) resolve, err = strconv.ParseBool(resolveString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", ResolveKey, err) err := fmt.Errorf("error parsing %s: %s", ResolveKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
} }
@ -112,7 +112,7 @@ func (m *Module) SearchGETHandler(c *gin.Context) {
i, err := strconv.ParseInt(limitString, 10, 32) i, err := strconv.ParseInt(limitString, 10, 32)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", LimitKey, err) err := fmt.Errorf("error parsing %s: %s", LimitKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
limit = int(i) limit = int(i)
@ -130,7 +130,7 @@ func (m *Module) SearchGETHandler(c *gin.Context) {
i, err := strconv.ParseInt(offsetString, 10, 32) i, err := strconv.ParseInt(offsetString, 10, 32)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", OffsetKey, err) err := fmt.Errorf("error parsing %s: %s", OffsetKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
offset = int(i) offset = int(i)
@ -143,7 +143,7 @@ func (m *Module) SearchGETHandler(c *gin.Context) {
following, err = strconv.ParseBool(followingString) following, err = strconv.ParseBool(followingString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", FollowingKey, err) err := fmt.Errorf("error parsing %s: %s", FollowingKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
} }
@ -163,7 +163,7 @@ func (m *Module) SearchGETHandler(c *gin.Context) {
results, errWithCode := m.processor.SearchGet(c.Request.Context(), authed, searchQuery) results, errWithCode := m.processor.SearchGet(c.Request.Context(), authed, searchQuery)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -72,25 +72,25 @@
func (m *Module) StatusBookmarkPOSTHandler(c *gin.Context) { func (m *Module) StatusBookmarkPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetStatusID := c.Param(IDKey) targetStatusID := c.Param(IDKey)
if targetStatusID == "" { if targetStatusID == "" {
err := errors.New("no status id specified") err := errors.New("no status id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
apiStatus, errWithCode := m.processor.StatusBookmark(c.Request.Context(), authed, targetStatusID) apiStatus, errWithCode := m.processor.StatusBookmark(c.Request.Context(), authed, targetStatusID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -75,25 +75,25 @@
func (m *Module) StatusBoostPOSTHandler(c *gin.Context) { func (m *Module) StatusBoostPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetStatusID := c.Param(IDKey) targetStatusID := c.Param(IDKey)
if targetStatusID == "" { if targetStatusID == "" {
err := errors.New("no status id specified") err := errors.New("no status id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
apiStatus, errWithCode := m.processor.StatusBoost(c.Request.Context(), authed, targetStatusID) apiStatus, errWithCode := m.processor.StatusBoost(c.Request.Context(), authed, targetStatusID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -68,20 +68,20 @@
func (m *Module) StatusBoostedByGETHandler(c *gin.Context) { func (m *Module) StatusBoostedByGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetStatusID := c.Param(IDKey) targetStatusID := c.Param(IDKey)
if targetStatusID == "" { if targetStatusID == "" {
err := errors.New("no status id specified") err := errors.New("no status id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
apiAccounts, errWithCode := m.processor.StatusBoostedBy(c.Request.Context(), authed, targetStatusID) apiAccounts, errWithCode := m.processor.StatusBoostedBy(c.Request.Context(), authed, targetStatusID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -74,25 +74,25 @@
func (m *Module) StatusContextGETHandler(c *gin.Context) { func (m *Module) StatusContextGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetStatusID := c.Param(IDKey) targetStatusID := c.Param(IDKey)
if targetStatusID == "" { if targetStatusID == "" {
err := errors.New("no status id specified") err := errors.New("no status id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
statusContext, errWithCode := m.processor.StatusGetContext(c.Request.Context(), authed, targetStatusID) statusContext, errWithCode := m.processor.StatusGetContext(c.Request.Context(), authed, targetStatusID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -75,18 +75,18 @@
func (m *Module) StatusCreatePOSTHandler(c *gin.Context) { func (m *Module) StatusCreatePOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form := &apimodel.AdvancedStatusCreateForm{} form := &apimodel.AdvancedStatusCreateForm{}
if err := c.ShouldBind(form); err != nil { if err := c.ShouldBind(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -100,13 +100,13 @@ func (m *Module) StatusCreatePOSTHandler(c *gin.Context) {
// form.Status += "\n\nsent from " + user + "'s iphone\n" // form.Status += "\n\nsent from " + user + "'s iphone\n"
if err := validateCreateStatus(form); err != nil { if err := validateCreateStatus(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
apiStatus, errWithCode := m.processor.StatusCreate(c.Request.Context(), authed, form) apiStatus, errWithCode := m.processor.StatusCreate(c.Request.Context(), authed, form)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -74,25 +74,25 @@
func (m *Module) StatusDELETEHandler(c *gin.Context) { func (m *Module) StatusDELETEHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetStatusID := c.Param(IDKey) targetStatusID := c.Param(IDKey)
if targetStatusID == "" { if targetStatusID == "" {
err := errors.New("no status id specified") err := errors.New("no status id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
apiStatus, errWithCode := m.processor.StatusDelete(c.Request.Context(), authed, targetStatusID) apiStatus, errWithCode := m.processor.StatusDelete(c.Request.Context(), authed, targetStatusID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -71,25 +71,25 @@
func (m *Module) StatusFavePOSTHandler(c *gin.Context) { func (m *Module) StatusFavePOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetStatusID := c.Param(IDKey) targetStatusID := c.Param(IDKey)
if targetStatusID == "" { if targetStatusID == "" {
err := errors.New("no status id specified") err := errors.New("no status id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
apiStatus, errWithCode := m.processor.StatusFave(c.Request.Context(), authed, targetStatusID) apiStatus, errWithCode := m.processor.StatusFave(c.Request.Context(), authed, targetStatusID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -72,25 +72,25 @@
func (m *Module) StatusFavedByGETHandler(c *gin.Context) { func (m *Module) StatusFavedByGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetStatusID := c.Param(IDKey) targetStatusID := c.Param(IDKey)
if targetStatusID == "" { if targetStatusID == "" {
err := errors.New("no status id specified") err := errors.New("no status id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
apiAccounts, errWithCode := m.processor.StatusFavedBy(c.Request.Context(), authed, targetStatusID) apiAccounts, errWithCode := m.processor.StatusFavedBy(c.Request.Context(), authed, targetStatusID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -71,25 +71,25 @@
func (m *Module) StatusGETHandler(c *gin.Context) { func (m *Module) StatusGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetStatusID := c.Param(IDKey) targetStatusID := c.Param(IDKey)
if targetStatusID == "" { if targetStatusID == "" {
err := errors.New("no status id specified") err := errors.New("no status id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
apiStatus, errWithCode := m.processor.StatusGet(c.Request.Context(), authed, targetStatusID) apiStatus, errWithCode := m.processor.StatusGet(c.Request.Context(), authed, targetStatusID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -72,25 +72,25 @@
func (m *Module) StatusUnbookmarkPOSTHandler(c *gin.Context) { func (m *Module) StatusUnbookmarkPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetStatusID := c.Param(IDKey) targetStatusID := c.Param(IDKey)
if targetStatusID == "" { if targetStatusID == "" {
err := errors.New("no status id specified") err := errors.New("no status id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
apiStatus, errWithCode := m.processor.StatusUnbookmark(c.Request.Context(), authed, targetStatusID) apiStatus, errWithCode := m.processor.StatusUnbookmark(c.Request.Context(), authed, targetStatusID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -72,25 +72,25 @@
func (m *Module) StatusUnboostPOSTHandler(c *gin.Context) { func (m *Module) StatusUnboostPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetStatusID := c.Param(IDKey) targetStatusID := c.Param(IDKey)
if targetStatusID == "" { if targetStatusID == "" {
err := errors.New("no status id specified") err := errors.New("no status id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
apiStatus, errWithCode := m.processor.StatusUnboost(c.Request.Context(), authed, targetStatusID) apiStatus, errWithCode := m.processor.StatusUnboost(c.Request.Context(), authed, targetStatusID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -71,25 +71,25 @@
func (m *Module) StatusUnfavePOSTHandler(c *gin.Context) { func (m *Module) StatusUnfavePOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
targetStatusID := c.Param(IDKey) targetStatusID := c.Param(IDKey)
if targetStatusID == "" { if targetStatusID == "" {
err := errors.New("no status id specified") err := errors.New("no status id specified")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
apiStatus, errWithCode := m.processor.StatusUnfave(c.Request.Context(), authed, targetStatusID) apiStatus, errWithCode := m.processor.StatusUnfave(c.Request.Context(), authed, targetStatusID)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -137,7 +137,7 @@ func (m *Module) StreamGETHandler(c *gin.Context) {
streamType := c.Query(StreamQueryKey) streamType := c.Query(StreamQueryKey)
if streamType == "" { if streamType == "" {
err := fmt.Errorf("no stream type provided under query key %s", StreamQueryKey) err := fmt.Errorf("no stream type provided under query key %s", StreamQueryKey)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -149,20 +149,20 @@ func (m *Module) StreamGETHandler(c *gin.Context) {
if token = c.GetHeader(AccessTokenHeader); token == "" { if token = c.GetHeader(AccessTokenHeader); token == "" {
const errStr = "no access token provided" const errStr = "no access token provided"
err := gtserror.NewErrorUnauthorized(errors.New(errStr), errStr) err := gtserror.NewErrorUnauthorized(errors.New(errStr), errStr)
apiutil.ErrorHandler(c, err, m.processor.InstanceGet) apiutil.ErrorHandler(c, err, m.processor.InstanceGetV1)
return return
} }
} }
account, errWithCode := m.processor.AuthorizeStreamingRequest(c.Request.Context(), token) account, errWithCode := m.processor.AuthorizeStreamingRequest(c.Request.Context(), token)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
stream, errWithCode := m.processor.OpenStreamForAccount(c.Request.Context(), account, streamType) stream, errWithCode := m.processor.OpenStreamForAccount(c.Request.Context(), account, streamType)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -112,12 +112,12 @@
func (m *Module) HomeTimelineGETHandler(c *gin.Context) { func (m *Module) HomeTimelineGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -145,7 +145,7 @@ func (m *Module) HomeTimelineGETHandler(c *gin.Context) {
i, err := strconv.ParseInt(limitString, 10, 32) i, err := strconv.ParseInt(limitString, 10, 32)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", LimitKey, err) err := fmt.Errorf("error parsing %s: %s", LimitKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
limit = int(i) limit = int(i)
@ -157,7 +157,7 @@ func (m *Module) HomeTimelineGETHandler(c *gin.Context) {
i, err := strconv.ParseBool(localString) i, err := strconv.ParseBool(localString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", LocalKey, err) err := fmt.Errorf("error parsing %s: %s", LocalKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
local = i local = i
@ -165,7 +165,7 @@ func (m *Module) HomeTimelineGETHandler(c *gin.Context) {
resp, errWithCode := m.processor.HomeTimelineGet(c.Request.Context(), authed, maxID, sinceID, minID, limit, local) resp, errWithCode := m.processor.HomeTimelineGet(c.Request.Context(), authed, maxID, sinceID, minID, limit, local)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -123,12 +123,12 @@ func (m *Module) PublicTimelineGETHandler(c *gin.Context) {
} }
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -156,7 +156,7 @@ func (m *Module) PublicTimelineGETHandler(c *gin.Context) {
i, err := strconv.ParseInt(limitString, 10, 32) i, err := strconv.ParseInt(limitString, 10, 32)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", LimitKey, err) err := fmt.Errorf("error parsing %s: %s", LimitKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
limit = int(i) limit = int(i)
@ -168,7 +168,7 @@ func (m *Module) PublicTimelineGETHandler(c *gin.Context) {
i, err := strconv.ParseBool(localString) i, err := strconv.ParseBool(localString)
if err != nil { if err != nil {
err := fmt.Errorf("error parsing %s: %s", LocalKey, err) err := fmt.Errorf("error parsing %s: %s", LocalKey, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
local = i local = i
@ -176,7 +176,7 @@ func (m *Module) PublicTimelineGETHandler(c *gin.Context) {
resp, errWithCode := m.processor.PublicTimelineGet(c.Request.Context(), authed, maxID, sinceID, minID, limit, local) resp, errWithCode := m.processor.PublicTimelineGet(c.Request.Context(), authed, maxID, sinceID, minID, limit, local)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -68,35 +68,35 @@
func (m *Module) PasswordChangePOSTHandler(c *gin.Context) { func (m *Module) PasswordChangePOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) authed, err := oauth.Authed(c, true, true, true, true)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
form := &apimodel.PasswordChangeRequest{} form := &apimodel.PasswordChangeRequest{}
if err := c.ShouldBind(form); err != nil { if err := c.ShouldBind(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if form.OldPassword == "" { if form.OldPassword == "" {
err := errors.New("password change request missing field old_password") err := errors.New("password change request missing field old_password")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if form.NewPassword == "" { if form.NewPassword == "" {
err := errors.New("password change request missing field new_password") err := errors.New("password change request missing field new_password")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if errWithCode := m.processor.UserChangePassword(c.Request.Context(), authed, form); errWithCode != nil { if errWithCode := m.processor.UserChangePassword(c.Request.Context(), authed, form); errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -41,7 +41,7 @@
func (m *Module) ServeFile(c *gin.Context) { func (m *Module) ServeFile(c *gin.Context) {
authed, err := oauth.Authed(c, false, false, false, false) authed, err := oauth.Authed(c, false, false, false, false)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err), m.processor.InstanceGetV1)
return return
} }
@ -51,28 +51,28 @@ func (m *Module) ServeFile(c *gin.Context) {
accountID := c.Param(AccountIDKey) accountID := c.Param(AccountIDKey)
if accountID == "" { if accountID == "" {
err := fmt.Errorf("missing %s from request", AccountIDKey) err := fmt.Errorf("missing %s from request", AccountIDKey)
apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err), m.processor.InstanceGetV1)
return return
} }
mediaType := c.Param(MediaTypeKey) mediaType := c.Param(MediaTypeKey)
if mediaType == "" { if mediaType == "" {
err := fmt.Errorf("missing %s from request", MediaTypeKey) err := fmt.Errorf("missing %s from request", MediaTypeKey)
apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err), m.processor.InstanceGetV1)
return return
} }
mediaSize := c.Param(MediaSizeKey) mediaSize := c.Param(MediaSizeKey)
if mediaSize == "" { if mediaSize == "" {
err := fmt.Errorf("missing %s from request", MediaSizeKey) err := fmt.Errorf("missing %s from request", MediaSizeKey)
apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err), m.processor.InstanceGetV1)
return return
} }
fileName := c.Param(FileNameKey) fileName := c.Param(FileNameKey)
if fileName == "" { if fileName == "" {
err := fmt.Errorf("missing %s from request", FileNameKey) err := fmt.Errorf("missing %s from request", FileNameKey)
apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err), m.processor.InstanceGetV1)
return return
} }
@ -83,7 +83,7 @@ func (m *Module) ServeFile(c *gin.Context) {
FileName: fileName, FileName: fileName,
}) })
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
@ -106,7 +106,7 @@ func (m *Module) ServeFile(c *gin.Context) {
// attempt to look up the content to provide a preview of the link, and they ask for text/html. // attempt to look up the content to provide a preview of the link, and they ask for text/html.
format, err := apiutil.NegotiateAccept(c, apiutil.MIME(content.ContentType)) format, err := apiutil.NegotiateAccept(c, apiutil.MIME(content.ContentType))
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -125,7 +125,7 @@ func (m *Module) ServeFile(c *gin.Context) {
if _, err := io.ReadFull(content.Content, b); err != nil && if _, err := io.ReadFull(content.Content, b); err != nil &&
(err != io.ErrUnexpectedEOF && err != io.EOF) { (err != io.ErrUnexpectedEOF && err != io.EOF) {
err = fmt.Errorf("ServeFile: error reading from content: %w", err) err = fmt.Errorf("ServeFile: error reading from content: %w", err)
apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
@ -142,7 +142,7 @@ func (m *Module) ServeFile(c *gin.Context) {
tfs, err := iotools.TempFileSeeker(r) tfs, err := iotools.TempFileSeeker(r)
if err != nil { if err != nil {
err = fmt.Errorf("ServeFile: error creating temp file seeker: %w", err) err = fmt.Errorf("ServeFile: error creating temp file seeker: %w", err)
apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1)
return return
} }
defer func() { defer func() {

View file

@ -20,93 +20,41 @@
import "mime/multipart" import "mime/multipart"
// Instance models information about this or another instance. // InstanceSettingsUpdateRequest models an instance update request.
// //
// swagger:model instance // swagger:ignore
type Instance struct { type InstanceSettingsUpdateRequest struct {
// The URI of the instance. // Title to use for the instance. Max 40 characters.
// example: https://gts.example.org Title *string `form:"title" json:"title" xml:"title"`
URI string `json:"uri,omitempty"` // Username for the instance contact account. Must be the username of an existing admin.
// The domain of accounts on this instance. ContactUsername *string `form:"contact_username" json:"contact_username" xml:"contact_username"`
// This will not necessarily be the same as // Email for reaching the instance administrator(s).
// simply the Host part of the URI. ContactEmail *string `form:"contact_email" json:"contact_email" xml:"contact_email"`
// example: example.org // Short description of the instance, max 500 chars. HTML formatting accepted.
AccountDomain string `json:"account_domain,omitempty"` ShortDescription *string `form:"short_description" json:"short_description" xml:"short_description"`
// The title of the instance. // Longer description of the instance, max 5,000 chars. HTML formatting accepted.
// example: GoToSocial Example Instance Description *string `form:"description" json:"description" xml:"description"`
Title string `json:"title,omitempty"` // Terms and conditions of the instance, max 5,000 chars. HTML formatting accepted.
// Description of the instance. Terms *string `form:"terms" json:"terms" xml:"terms"`
// // Image to use as the instance thumbnail.
// Should be HTML formatted, but might be plaintext. Avatar *multipart.FileHeader `form:"thumbnail" json:"thumbnail" xml:"thumbnail"`
// // Image description for the instance avatar.
// This should be displayed on the 'about' page for an instance. AvatarDescription *string `form:"thumbnail_description" json:"thumbnail_description" xml:"thumbnail_description"`
Description string `json:"description"` // Image to use as the instance header.
// A shorter description of the instance. Header *multipart.FileHeader `form:"header" json:"header" xml:"header"`
//
// Should be HTML formatted, but might be plaintext.
//
// This should be displayed on the instance splash/landing page.
ShortDescription string `json:"short_description"`
// An email address that may be used for inquiries.
// example: admin@example.org
Email string `json:"email"`
// The version of GoToSocial installed on the instance.
//
// This will contain at least a semantic version number.
//
// It may also contain, after a space, the short git commit ID of the running software.
//
// example: 0.1.1 cb85f65
Version string `json:"version"`
// Primary language of the instance.
// example: en
Languages []string `json:"languages,omitempty"`
// New account registrations are enabled on this instance.
Registrations bool `json:"registrations"`
// New account registrations require admin approval.
ApprovalRequired bool `json:"approval_required"`
// Invites are enabled on this instance.
InvitesEnabled bool `json:"invites_enabled"`
// Configuration object containing values about status limits etc.
// This key/value will be omitted for remote instances.
Configuration *InstanceConfiguration `json:"configuration,omitempty"`
// URLs of interest for client applications.
URLS *InstanceURLs `json:"urls,omitempty"`
// Statistics about the instance: number of posts, accounts, etc.
Stats map[string]int `json:"stats,omitempty"`
// URL of the instance avatar/banner image.
// example: https://example.org/files/instance/thumbnail.jpeg
Thumbnail string `json:"thumbnail"`
// MIME type of the instance thumbnail.
// example: image/png
ThumbnailType string `json:"thumbnail_type,omitempty"`
// Description of the instance thumbnail.
// example: picture of a cute lil' friendly sloth
ThumbnailDescription string `json:"thumbnail_description,omitempty"`
// Contact account for the instance.
ContactAccount *Account `json:"contact_account,omitempty"`
// Maximum allowed length of a post on this instance, in characters.
//
// This is provided for compatibility with Tusky and other apps.
//
// example: 5000
MaxTootChars uint `json:"max_toot_chars"`
} }
// InstanceConfiguration models instance configuration parameters. // InstanceConfigurationAccounts models instance account config parameters.
// //
// swagger:model instanceConfiguration // swagger:model instanceConfigurationAccounts
type InstanceConfiguration struct { type InstanceConfigurationAccounts struct {
// Instance configuration pertaining to status limits. // Whether or not accounts on this instance are allowed to upload custom CSS for profiles and statuses.
Statuses *InstanceConfigurationStatuses `json:"statuses"` //
// Instance configuration pertaining to media attachment types + size limits. // example: false
MediaAttachments *InstanceConfigurationMediaAttachments `json:"media_attachments"` AllowCustomCSS bool `json:"allow_custom_css"`
// Instance configuration pertaining to poll limits. // The maximum number of featured tags allowed for each account.
Polls *InstanceConfigurationPolls `json:"polls"` // Currently not implemented, so this is hardcoded to 10.
// Instance configuration pertaining to accounts. MaxFeaturedTags int `json:"max_featured_tags"`
Accounts *InstanceConfigurationAccounts `json:"accounts"`
// Instance configuration pertaining to emojis.
Emojis *InstanceConfigurationEmojis `json:"emojis"`
} }
// InstanceConfigurationStatuses models instance status config parameters. // InstanceConfigurationStatuses models instance status config parameters.
@ -185,14 +133,6 @@ type InstanceConfigurationPolls struct {
MaxExpiration int `json:"max_expiration"` MaxExpiration int `json:"max_expiration"`
} }
// InstanceConfigurationAccounts models instance account config parameters.
type InstanceConfigurationAccounts struct {
// Whether or not accounts on this instance are allowed to upload custom CSS for profiles and statuses.
//
// example: false
AllowCustomCSS bool `json:"allow_custom_css"`
}
// InstanceConfigurationEmojis models instance emoji config parameters. // InstanceConfigurationEmojis models instance emoji config parameters.
type InstanceConfigurationEmojis struct { type InstanceConfigurationEmojis struct {
// Max allowed emoji image size in bytes. // Max allowed emoji image size in bytes.
@ -200,36 +140,3 @@ type InstanceConfigurationEmojis struct {
// example: 51200 // example: 51200
EmojiSizeLimit int `json:"emoji_size_limit"` EmojiSizeLimit int `json:"emoji_size_limit"`
} }
// InstanceURLs models instance-relevant URLs for client application consumption.
//
// swagger:model instanceURLs
type InstanceURLs struct {
// Websockets address for status and notification streaming.
// example: wss://example.org
StreamingAPI string `json:"streaming_api"`
}
// InstanceSettingsUpdateRequest models an instance update request.
//
// swagger:ignore
type InstanceSettingsUpdateRequest struct {
// Title to use for the instance. Max 40 characters.
Title *string `form:"title" json:"title" xml:"title"`
// Username for the instance contact account. Must be the username of an existing admin.
ContactUsername *string `form:"contact_username" json:"contact_username" xml:"contact_username"`
// Email for reaching the instance administrator(s).
ContactEmail *string `form:"contact_email" json:"contact_email" xml:"contact_email"`
// Short description of the instance, max 500 chars. HTML formatting accepted.
ShortDescription *string `form:"short_description" json:"short_description" xml:"short_description"`
// Longer description of the instance, max 5,000 chars. HTML formatting accepted.
Description *string `form:"description" json:"description" xml:"description"`
// Terms and conditions of the instance, max 5,000 chars. HTML formatting accepted.
Terms *string `form:"terms" json:"terms" xml:"terms"`
// Image to use as the instance thumbnail.
Avatar *multipart.FileHeader `form:"thumbnail" json:"thumbnail" xml:"thumbnail"`
// Image description for the instance avatar.
AvatarDescription *string `form:"thumbnail_description" json:"thumbnail_description" xml:"thumbnail_description"`
// Image to use as the instance header.
Header *multipart.FileHeader `form:"header" json:"header" xml:"header"`
}

View file

@ -0,0 +1,117 @@
/*
GoToSocial
Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package model
// InstanceV1 models information about this instance.
//
// swagger:model instanceV1
type InstanceV1 struct {
// The URI of the instance.
// example: https://gts.example.org
URI string `json:"uri,omitempty"`
// The domain of accounts on this instance.
// This will not necessarily be the same as
// simply the Host part of the URI.
// example: example.org
AccountDomain string `json:"account_domain,omitempty"`
// The title of the instance.
// example: GoToSocial Example Instance
Title string `json:"title,omitempty"`
// Description of the instance.
//
// Should be HTML formatted, but might be plaintext.
//
// This should be displayed on the 'about' page for an instance.
Description string `json:"description"`
// A shorter description of the instance.
//
// Should be HTML formatted, but might be plaintext.
//
// This should be displayed on the instance splash/landing page.
ShortDescription string `json:"short_description"`
// An email address that may be used for inquiries.
// example: admin@example.org
Email string `json:"email"`
// The version of GoToSocial installed on the instance.
//
// This will contain at least a semantic version number.
//
// It may also contain, after a space, the short git commit ID of the running software.
//
// example: 0.1.1 cb85f65
Version string `json:"version"`
// Primary language of the instance.
// example: en
Languages []string `json:"languages,omitempty"`
// New account registrations are enabled on this instance.
Registrations bool `json:"registrations"`
// New account registrations require admin approval.
ApprovalRequired bool `json:"approval_required"`
// Invites are enabled on this instance.
InvitesEnabled bool `json:"invites_enabled"`
// Configuration object containing values about status limits etc.
// This key/value will be omitted for remote instances.
Configuration InstanceV1Configuration `json:"configuration,omitempty"`
// URLs of interest for client applications.
URLs InstanceV1URLs `json:"urls,omitempty"`
// Statistics about the instance: number of posts, accounts, etc.
Stats map[string]int `json:"stats,omitempty"`
// URL of the instance avatar/banner image.
// example: https://example.org/files/instance/thumbnail.jpeg
Thumbnail string `json:"thumbnail"`
// MIME type of the instance thumbnail.
// example: image/png
ThumbnailType string `json:"thumbnail_type,omitempty"`
// Description of the instance thumbnail.
// example: picture of a cute lil' friendly sloth
ThumbnailDescription string `json:"thumbnail_description,omitempty"`
// Contact account for the instance.
ContactAccount *Account `json:"contact_account,omitempty"`
// Maximum allowed length of a post on this instance, in characters.
//
// This is provided for compatibility with Tusky and other apps.
//
// example: 5000
MaxTootChars uint `json:"max_toot_chars"`
}
// InstanceV1URLs models instance-relevant URLs for client application consumption.
//
// swagger:model instanceV1URLs
type InstanceV1URLs struct {
// Websockets address for status and notification streaming.
// example: wss://example.org
StreamingAPI string `json:"streaming_api"`
}
// InstanceV1Configuration models instance configuration parameters.
//
// swagger:model instanceV1Configuration
type InstanceV1Configuration struct {
// Instance configuration pertaining to status limits.
Statuses InstanceConfigurationStatuses `json:"statuses"`
// Instance configuration pertaining to media attachment types + size limits.
MediaAttachments InstanceConfigurationMediaAttachments `json:"media_attachments"`
// Instance configuration pertaining to poll limits.
Polls InstanceConfigurationPolls `json:"polls"`
// Instance configuration pertaining to accounts.
Accounts InstanceConfigurationAccounts `json:"accounts"`
// Instance configuration pertaining to emojis.
Emojis InstanceConfigurationEmojis `json:"emojis"`
}

View file

@ -0,0 +1,189 @@
/*
GoToSocial
Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package model
// InstanceV2 models information about this instance.
//
// swagger:model instanceV2
type InstanceV2 struct {
// The domain of the instance.
// example: gts.example.org
Domain string `json:"domain"`
// The domain of accounts on this instance.
// This will not necessarily be the same as
// domain.
// example: example.org
AccountDomain string `json:"account_domain"`
// The title of the instance.
// example: GoToSocial Example Instance
Title string `json:"title"`
// The version of GoToSocial installed on the instance.
//
// This will contain at least a semantic version number.
//
// It may also contain, after a space, the short git commit ID of the running software.
//
// example: 0.1.1 cb85f65
Version string `json:"version"`
// The URL for the source code of the software running on this instance, in keeping with AGPL license requirements.
// example: https://github.com/superseriousbusiness/gotosocial
SourceURL string `json:"source_url"`
// Description of the instance.
//
// Should be HTML formatted, but might be plaintext.
//
// This should be displayed on the 'about' page for an instance.
Description string `json:"description"`
// Basic anonymous usage data for this instance.
Usage InstanceV2Usage `json:"usage"`
// An image used to represent this instance.
Thumbnail InstanceV2Thumbnail `json:"thumbnail"`
// Primary languages of the instance + moderators/admins.
// example: ["en"]
Languages []string `json:"languages"`
// Configured values and limits for this instance.
Configuration InstanceV2Configuration `json:"configuration"`
// Information about registering for this instance.
Registrations InstanceV2Registrations `json:"registrations"`
// Hints related to contacting a representative of the instance.
Contact InstanceV2Contact `json:"contact"`
// An itemized list of rules for this website.
// Currently not implemented (will always be empty array).
Rules []interface{} `json:"rules"`
}
// Usage data for this instance.
//
// swagger:model instanceV2Usage
type InstanceV2Usage struct {
Users InstanceV2Users `json:"users"`
}
// Usage data related to users on this instance.
//
// swagger:model instanceV2Users
type InstanceV2Users struct {
// The number of active users in the past 4 weeks.
// Currently not implemented: will always be 0.
// example: 0
ActiveMonth int `json:"active_month"`
}
// An image used to represent this instance.
//
// swagger:model instanceV2Thumbnail
type InstanceV2Thumbnail struct {
// The URL for the thumbnail image.
// example: https://example.org/fileserver/01BPSX2MKCRVMD4YN4D71G9CP5/attachment/original/01H88X0KQ2DFYYDSWYP93VDJZA.png
URL string `json:"url"`
// MIME type of the instance thumbnail.
// Key/value not set if thumbnail image type unknown.
// example: image/png
Type string `json:"thumbnail_type,omitempty"`
// Description of the instance thumbnail.
// Key/value not set if no description available.
// example: picture of a cute lil' friendly sloth
Description string `json:"thumbnail_description,omitempty"`
// A hash computed by the BlurHash algorithm, for generating colorful preview thumbnails when media has not been downloaded yet.
// Key/value not set if no blurhash available.
// example: UeKUpFxuo~R%0nW;WCnhF6RjaJt757oJodS$
Blurhash string `json:"blurhash,omitempty"`
// Links to scaled resolution images, for high DPI screens.
// Key/value not set if no extra versions available.
Versions *InstanceV2ThumbnailVersions `json:"versions,omitempty"`
}
// Links to scaled resolution images, for high DPI screens.
//
// swagger:model instanceV2ThumbnailVersions
type InstanceV2ThumbnailVersions struct {
// The URL for the thumbnail image at 1x resolution.
// Key/value not set if scaled versions not available.
Size1URL string `json:"@1x,omitempty"`
// The URL for the thumbnail image at 2x resolution.
// Key/value not set if scaled versions not available.
Size2URL string `json:"@2x,omitempty"`
}
// InstanceV2URLs models instance-relevant URLs for client application consumption.
//
// swagger:model instanceV1URLs
type InstanceV2URLs struct {
// Websockets address for status and notification streaming.
// example: wss://example.org
Streaming string `json:"streaming"`
}
// Hints related to translation.
//
// swagger:model instanceV2ConfigurationTranslation
type InstanceV2ConfigurationTranslation struct {
// Whether the Translations API is available on this instance.
// Not implemented so this value is always false.
Enabled bool `json:"enabled"`
}
// Configured values and limits for this instance.
//
// swagger:model instanceV2Configuration
type InstanceV2Configuration struct {
// URLs of interest for clients apps.
URLs InstanceV2URLs `json:"urls"`
// Limits related to accounts.
Accounts InstanceConfigurationAccounts `json:"accounts"`
// Limits related to authoring statuses.
Statuses InstanceConfigurationStatuses `json:"statuses"`
// Hints for which attachments will be accepted.
MediaAttachments InstanceConfigurationMediaAttachments `json:"media_attachments"`
// Limits related to polls.
Polls InstanceConfigurationPolls `json:"polls"`
// Hints related to translation.
Translation InstanceV2ConfigurationTranslation `json:"translation"`
// Instance configuration pertaining to emojis.
Emojis InstanceConfigurationEmojis `json:"emojis"`
}
// Information about registering for this instance.
//
// swagger:model instanceV2Registrations
type InstanceV2Registrations struct {
// Whether registrations are enabled.
// example: false
Enabled bool `json:"enabled"`
// Whether registrations require moderator approval.
// example: true
ApprovalRequired bool `json:"approval_required"`
// A custom message (html string) to be shown when registrations are closed.
// Value will be null if no message is set.
// example: <p>Registrations are currently closed on example.org because of spam bots!</p>
Message *string `json:"message"`
}
// Hints related to contacting a representative of the instance.
//
// swagger:model instanceV2Contact
type InstanceV2Contact struct {
// An email address that can be messaged regarding inquiries or issues.
// Empty string if no email address set.
// example: someone@example.org
Email string `json:"email"`
// An account that can be contacted regarding inquiries or issues.
// Key/value not present if no contact account set.
Account *Account `json:"account,omitempty"`
}

View file

@ -46,19 +46,19 @@
// "$ref": "#/definitions/nodeinfo" // "$ref": "#/definitions/nodeinfo"
func (m *Module) NodeInfo2GETHandler(c *gin.Context) { func (m *Module) NodeInfo2GETHandler(c *gin.Context) {
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
nodeInfo, errWithCode := m.processor.GetNodeInfo(c.Request.Context()) nodeInfo, errWithCode := m.processor.GetNodeInfo(c.Request.Context())
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }
b, err := json.Marshal(nodeInfo) b, err := json.Marshal(nodeInfo)
if err != nil { if err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1)
return return
} }

View file

@ -25,7 +25,6 @@
"codeberg.org/gruf/go-kv" "codeberg.org/gruf/go-kv"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/log" "github.com/superseriousbusiness/gotosocial/internal/log"
) )
@ -41,11 +40,10 @@
// 404 header and footer. // 404 header and footer.
// //
// If an error is returned by InstanceGet, the function will panic. // If an error is returned by InstanceGet, the function will panic.
func NotFoundHandler(c *gin.Context, instanceGet func(ctx context.Context, domain string) (*apimodel.Instance, gtserror.WithCode), accept string) { func NotFoundHandler(c *gin.Context, instanceGet func(ctx context.Context) (*apimodel.InstanceV1, gtserror.WithCode), accept string) {
switch accept { switch accept {
case string(TextHTML): case string(TextHTML):
host := config.GetHost() instance, err := instanceGet(c.Request.Context())
instance, err := instanceGet(c.Request.Context(), host)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -61,11 +59,10 @@ func NotFoundHandler(c *gin.Context, instanceGet func(ctx context.Context, domai
// genericErrorHandler is a more general version of the NotFoundHandler, which can // genericErrorHandler is a more general version of the NotFoundHandler, which can
// be used for serving either generic error pages with some rendered help text, // be used for serving either generic error pages with some rendered help text,
// or just some error json if the caller prefers (or has no preference). // or just some error json if the caller prefers (or has no preference).
func genericErrorHandler(c *gin.Context, instanceGet func(ctx context.Context, domain string) (*apimodel.Instance, gtserror.WithCode), accept string, errWithCode gtserror.WithCode) { func genericErrorHandler(c *gin.Context, instanceGet func(ctx context.Context) (*apimodel.InstanceV1, gtserror.WithCode), accept string, errWithCode gtserror.WithCode) {
switch accept { switch accept {
case string(TextHTML): case string(TextHTML):
host := config.GetHost() instance, err := instanceGet(c.Request.Context())
instance, err := instanceGet(c.Request.Context(), host)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -85,7 +82,7 @@ func genericErrorHandler(c *gin.Context, instanceGet func(ctx context.Context, d
// the caller prefers to see an html page with the error rendered there. If not, or // the caller prefers to see an html page with the error rendered there. If not, or
// if something goes wrong during the function, it will recover and just try to serve // if something goes wrong during the function, it will recover and just try to serve
// an appropriate application/json content-type error. // an appropriate application/json content-type error.
func ErrorHandler(c *gin.Context, errWithCode gtserror.WithCode, instanceGet func(ctx context.Context, domain string) (*apimodel.Instance, gtserror.WithCode)) { func ErrorHandler(c *gin.Context, errWithCode gtserror.WithCode, instanceGet func(ctx context.Context) (*apimodel.InstanceV1, gtserror.WithCode)) {
// set the error on the gin context so that it can be logged // set the error on the gin context so that it can be logged
// in the gin logger middleware (internal/router/logger.go) // in the gin logger middleware (internal/router/logger.go)
c.Error(errWithCode) //nolint:errcheck c.Error(errWithCode) //nolint:errcheck

View file

@ -46,13 +46,13 @@
// "$ref": "#/definitions/wellKnownResponse" // "$ref": "#/definitions/wellKnownResponse"
func (m *Module) NodeInfoWellKnownGETHandler(c *gin.Context) { func (m *Module) NodeInfoWellKnownGETHandler(c *gin.Context) {
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
resp, errWithCode := m.processor.GetNodeInfoRel(c.Request.Context()) resp, errWithCode := m.processor.GetNodeInfoRel(c.Request.Context())
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -57,33 +57,33 @@
// "$ref": "#/definitions/wellKnownResponse" // "$ref": "#/definitions/wellKnownResponse"
func (m *Module) WebfingerGETRequest(c *gin.Context) { func (m *Module) WebfingerGETRequest(c *gin.Context) {
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
resourceQuery, set := c.GetQuery("resource") resourceQuery, set := c.GetQuery("resource")
if !set || resourceQuery == "" { if !set || resourceQuery == "" {
err := errors.New("no 'resource' in request query") err := errors.New("no 'resource' in request query")
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
requestedUsername, requestedHost, err := util.ExtractWebfingerParts(resourceQuery) requestedUsername, requestedHost, err := util.ExtractWebfingerParts(resourceQuery)
if err != nil { if err != nil {
err := fmt.Errorf("bad webfinger request with resource query %s: %w", resourceQuery, err) err := fmt.Errorf("bad webfinger request with resource query %s: %w", resourceQuery, err)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
if requestedHost != config.GetHost() && requestedHost != config.GetAccountDomain() { if requestedHost != config.GetHost() && requestedHost != config.GetAccountDomain() {
err := fmt.Errorf("requested host %s does not belong to this instance", requestedHost) err := fmt.Errorf("requested host %s does not belong to this instance", requestedHost)
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return return
} }
resp, errWithCode := m.processor.GetWebfingerAccount(c.Request.Context(), requestedUsername) resp, errWithCode := m.processor.GetWebfingerAccount(c.Request.Context(), requestedUsername)
if errWithCode != nil { if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return return
} }

View file

@ -33,13 +33,35 @@
"github.com/superseriousbusiness/gotosocial/internal/validate" "github.com/superseriousbusiness/gotosocial/internal/validate"
) )
func (p *processor) InstanceGet(ctx context.Context, domain string) (*apimodel.Instance, gtserror.WithCode) { func (p *processor) getThisInstance(ctx context.Context) (*gtsmodel.Instance, error) {
i := &gtsmodel.Instance{} i := &gtsmodel.Instance{}
if err := p.db.GetWhere(ctx, []db.Where{{Key: "domain", Value: domain}}, i); err != nil { if err := p.db.GetWhere(ctx, []db.Where{{Key: "domain", Value: config.GetHost()}}, i); err != nil {
return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error fetching instance %s: %s", domain, err)) return nil, err
}
return i, nil
}
func (p *processor) InstanceGetV1(ctx context.Context) (*apimodel.InstanceV1, gtserror.WithCode) {
i, err := p.getThisInstance(ctx)
if err != nil {
return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error fetching instance: %s", err))
} }
ai, err := p.tc.InstanceToAPIInstance(ctx, i) ai, err := p.tc.InstanceToAPIV1Instance(ctx, i)
if err != nil {
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting instance to api representation: %s", err))
}
return ai, nil
}
func (p *processor) InstanceGetV2(ctx context.Context) (*apimodel.InstanceV2, gtserror.WithCode) {
i, err := p.getThisInstance(ctx)
if err != nil {
return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error fetching instance: %s", err))
}
ai, err := p.tc.InstanceToAPIV2Instance(ctx, i)
if err != nil { if err != nil {
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting instance to api representation: %s", err)) return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting instance to api representation: %s", err))
} }
@ -98,7 +120,7 @@ func (p *processor) InstancePeersGet(ctx context.Context, includeSuspended bool,
return domains, nil return domains, nil
} }
func (p *processor) InstancePatch(ctx context.Context, form *apimodel.InstanceSettingsUpdateRequest) (*apimodel.Instance, gtserror.WithCode) { func (p *processor) InstancePatch(ctx context.Context, form *apimodel.InstanceSettingsUpdateRequest) (*apimodel.InstanceV1, gtserror.WithCode) {
// fetch the instance entry from the db for processing // fetch the instance entry from the db for processing
i := &gtsmodel.Instance{} i := &gtsmodel.Instance{}
host := config.GetHost() host := config.GetHost()
@ -235,7 +257,7 @@ func (p *processor) InstancePatch(ctx context.Context, form *apimodel.InstanceSe
} }
} }
ai, err := p.tc.InstanceToAPIInstance(ctx, i) ai, err := p.tc.InstanceToAPIV1Instance(ctx, i)
if err != nil { if err != nil {
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting instance to api representation: %s", err)) return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting instance to api representation: %s", err))
} }

View file

@ -170,13 +170,15 @@ type Processor interface {
// FollowRequestReject handles the rejection of a follow request from the given account ID. // FollowRequestReject handles the rejection of a follow request from the given account ID.
FollowRequestReject(ctx context.Context, auth *oauth.Auth, accountID string) (*apimodel.Relationship, gtserror.WithCode) FollowRequestReject(ctx context.Context, auth *oauth.Auth, accountID string) (*apimodel.Relationship, gtserror.WithCode)
// InstanceGet retrieves instance information for serving at api/v1/instance // InstanceGetV1 retrieves instance information for serving at api/v1/instance
InstanceGet(ctx context.Context, domain string) (*apimodel.Instance, gtserror.WithCode) InstanceGetV1(ctx context.Context) (*apimodel.InstanceV1, gtserror.WithCode)
// InstanceGetV1 retrieves instance information for serving at api/v2/instance
InstanceGetV2(ctx context.Context) (*apimodel.InstanceV2, gtserror.WithCode)
InstancePeersGet(ctx context.Context, includeSuspended bool, includeOpen bool, flat bool) (interface{}, gtserror.WithCode) InstancePeersGet(ctx context.Context, includeSuspended bool, includeOpen bool, flat bool) (interface{}, gtserror.WithCode)
// InstancePatch updates this instance according to the given form. // InstancePatch updates this instance according to the given form.
// //
// It should already be ascertained that the requesting account is authenticated and an admin. // It should already be ascertained that the requesting account is authenticated and an admin.
InstancePatch(ctx context.Context, form *apimodel.InstanceSettingsUpdateRequest) (*apimodel.Instance, gtserror.WithCode) InstancePatch(ctx context.Context, form *apimodel.InstanceSettingsUpdateRequest) (*apimodel.InstanceV1, gtserror.WithCode)
// MediaCreate handles the creation of a media attachment, using the given form. // MediaCreate handles the creation of a media attachment, using the given form.
MediaCreate(ctx context.Context, authed *oauth.Auth, form *apimodel.AttachmentRequest) (*apimodel.Attachment, gtserror.WithCode) MediaCreate(ctx context.Context, authed *oauth.Auth, form *apimodel.AttachmentRequest) (*apimodel.Attachment, gtserror.WithCode)

View file

@ -113,7 +113,7 @@ func dereferenceByAPIV1Instance(ctx context.Context, t *transport, iri *url.URL)
} }
// try to parse the returned bytes directly into an Instance model // try to parse the returned bytes directly into an Instance model
apiResp := &apimodel.Instance{} apiResp := &apimodel.InstanceV1{}
if err := json.Unmarshal(b, apiResp); err != nil { if err := json.Unmarshal(b, apiResp); err != nil {
return nil, err return nil, err
} }

View file

@ -79,8 +79,10 @@ type TypeConverter interface {
StatusToAPIStatus(ctx context.Context, s *gtsmodel.Status, requestingAccount *gtsmodel.Account) (*apimodel.Status, error) StatusToAPIStatus(ctx context.Context, s *gtsmodel.Status, requestingAccount *gtsmodel.Account) (*apimodel.Status, error)
// VisToAPIVis converts a gts visibility into its api equivalent // VisToAPIVis converts a gts visibility into its api equivalent
VisToAPIVis(ctx context.Context, m gtsmodel.Visibility) apimodel.Visibility VisToAPIVis(ctx context.Context, m gtsmodel.Visibility) apimodel.Visibility
// InstanceToAPIInstance converts a gts instance into its api equivalent for serving at /api/v1/instance // InstanceToAPIV1Instance converts a gts instance into its api equivalent for serving at /api/v1/instance
InstanceToAPIInstance(ctx context.Context, i *gtsmodel.Instance) (*apimodel.Instance, error) InstanceToAPIV1Instance(ctx context.Context, i *gtsmodel.Instance) (*apimodel.InstanceV1, error)
// InstanceToAPIV2Instance converts a gts instance into its api equivalent for serving at /api/v2/instance
InstanceToAPIV2Instance(ctx context.Context, i *gtsmodel.Instance) (*apimodel.InstanceV2, error)
// RelationshipToAPIRelationship converts a gts relationship into its api equivalent for serving in various places // RelationshipToAPIRelationship converts a gts relationship into its api equivalent for serving in various places
RelationshipToAPIRelationship(ctx context.Context, r *gtsmodel.Relationship) (*apimodel.Relationship, error) RelationshipToAPIRelationship(ctx context.Context, r *gtsmodel.Relationship) (*apimodel.Relationship, error)
// NotificationToAPINotification converts a gts notification into a api notification // NotificationToAPINotification converts a gts notification into a api notification

View file

@ -20,7 +20,6 @@
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"math" "math"
"strconv" "strconv"
@ -43,6 +42,8 @@
instanceMediaAttachmentsVideoFrameRateLimit = 60 instanceMediaAttachmentsVideoFrameRateLimit = 60
instancePollsMinExpiration = 300 // seconds instancePollsMinExpiration = 300 // seconds
instancePollsMaxExpiration = 2629746 // seconds instancePollsMaxExpiration = 2629746 // seconds
instanceAccountsMaxFeaturedTags = 10
instanceSourceURL = "https://github.com/superseriousbusiness/gotosocial"
) )
func (c *converter) AccountToAPIAccountSensitive(ctx context.Context, a *gtsmodel.Account) (*apimodel.Account, error) { func (c *converter) AccountToAPIAccountSensitive(ctx context.Context, a *gtsmodel.Account) (*apimodel.Account, error) {
@ -675,113 +676,189 @@ func (c *converter) VisToAPIVis(ctx context.Context, m gtsmodel.Visibility) apim
return "" return ""
} }
func (c *converter) InstanceToAPIInstance(ctx context.Context, i *gtsmodel.Instance) (*apimodel.Instance, error) { func (c *converter) InstanceToAPIV1Instance(ctx context.Context, i *gtsmodel.Instance) (*apimodel.InstanceV1, error) {
mi := &apimodel.Instance{ instance := &apimodel.InstanceV1{
URI: i.URI, URI: i.URI,
AccountDomain: config.GetAccountDomain(),
Title: i.Title, Title: i.Title,
Description: i.Description, Description: i.Description,
ShortDescription: i.ShortDescription, ShortDescription: i.ShortDescription,
Email: i.ContactEmail, Email: i.ContactEmail,
Version: i.Version, Version: config.GetSoftwareVersion(),
Stats: make(map[string]int), Languages: []string{}, // todo: not supported yet
Registrations: config.GetAccountsRegistrationOpen(),
ApprovalRequired: config.GetAccountsApprovalRequired(),
InvitesEnabled: false, // todo: not supported yet
MaxTootChars: uint(config.GetStatusesMaxChars()),
} }
// if the requested instance is *this* instance, we can add some extra information // configuration
if host := config.GetHost(); i.Domain == host { instance.Configuration.Statuses.MaxCharacters = config.GetStatusesMaxChars()
mi.AccountDomain = config.GetAccountDomain() instance.Configuration.Statuses.MaxMediaAttachments = config.GetStatusesMediaMaxFiles()
instance.Configuration.Statuses.CharactersReservedPerURL = instanceStatusesCharactersReservedPerURL
instance.Configuration.MediaAttachments.SupportedMimeTypes = media.SupportedMIMETypes
instance.Configuration.MediaAttachments.ImageSizeLimit = int(config.GetMediaImageMaxSize())
instance.Configuration.MediaAttachments.ImageMatrixLimit = instanceMediaAttachmentsImageMatrixLimit
instance.Configuration.MediaAttachments.VideoSizeLimit = int(config.GetMediaVideoMaxSize())
instance.Configuration.MediaAttachments.VideoFrameRateLimit = instanceMediaAttachmentsVideoFrameRateLimit
instance.Configuration.MediaAttachments.VideoMatrixLimit = instanceMediaAttachmentsVideoMatrixLimit
instance.Configuration.Polls.MaxOptions = config.GetStatusesPollMaxOptions()
instance.Configuration.Polls.MaxCharactersPerOption = config.GetStatusesPollOptionMaxChars()
instance.Configuration.Polls.MinExpiration = instancePollsMinExpiration
instance.Configuration.Polls.MaxExpiration = instancePollsMaxExpiration
instance.Configuration.Accounts.AllowCustomCSS = config.GetAccountsAllowCustomCSS()
instance.Configuration.Accounts.MaxFeaturedTags = instanceAccountsMaxFeaturedTags
instance.Configuration.Emojis.EmojiSizeLimit = int(config.GetMediaEmojiLocalMaxSize())
if ia, err := c.db.GetInstanceAccount(ctx, ""); err == nil { // URLs
// assume default logo instance.URLs.StreamingAPI = "wss://" + i.Domain
mi.Thumbnail = config.GetProtocol() + "://" + host + "/assets/logo.png"
// take instance account avatar as instance thumbnail if we can // statistics
if ia.AvatarMediaAttachmentID != "" { stats := make(map[string]int, 3)
if ia.AvatarMediaAttachment == nil { userCount, err := c.db.CountInstanceUsers(ctx, i.Domain)
avi, err := c.db.GetAttachmentByID(ctx, ia.AvatarMediaAttachmentID) if err != nil {
if err == nil { return nil, fmt.Errorf("InstanceToAPIV1Instance: db error getting counting instance users: %w", err)
ia.AvatarMediaAttachment = avi }
} else if !errors.Is(err, db.ErrNoEntries) { stats["user_count"] = userCount
log.Errorf("InstanceToAPIInstance: error getting instance avatar attachment with id %s: %s", ia.AvatarMediaAttachmentID, err)
}
}
if ia.AvatarMediaAttachment != nil { statusCount, err := c.db.CountInstanceStatuses(ctx, i.Domain)
mi.Thumbnail = ia.AvatarMediaAttachment.URL if err != nil {
mi.ThumbnailType = ia.AvatarMediaAttachment.File.ContentType return nil, fmt.Errorf("InstanceToAPIV1Instance: db error getting counting instance statuses: %w", err)
mi.ThumbnailDescription = ia.AvatarMediaAttachment.Description }
} stats["status_count"] = statusCount
domainCount, err := c.db.CountInstanceDomains(ctx, i.Domain)
if err != nil {
return nil, fmt.Errorf("InstanceToAPIV1Instance: db error getting counting instance domains: %w", err)
}
stats["domain_count"] = domainCount
instance.Stats = stats
// thumbnail
iAccount, err := c.db.GetInstanceAccount(ctx, "")
if err != nil {
return nil, fmt.Errorf("InstanceToAPIV1Instance: db error getting instance account: %w", err)
}
if iAccount.AvatarMediaAttachmentID != "" {
if iAccount.AvatarMediaAttachment == nil {
avi, err := c.db.GetAttachmentByID(ctx, iAccount.AvatarMediaAttachmentID)
if err != nil {
return nil, fmt.Errorf("InstanceToAPIInstance: error getting instance avatar attachment with id %s: %w", iAccount.AvatarMediaAttachmentID, err)
} }
iAccount.AvatarMediaAttachment = avi
} }
userCount, err := c.db.CountInstanceUsers(ctx, host) instance.Thumbnail = iAccount.AvatarMediaAttachment.URL
if err == nil { instance.ThumbnailType = iAccount.AvatarMediaAttachment.File.ContentType
mi.Stats["user_count"] = userCount instance.ThumbnailDescription = iAccount.AvatarMediaAttachment.Description
} } else {
instance.Thumbnail = config.GetProtocol() + "://" + i.Domain + "/assets/logo.png" // default thumb
statusCount, err := c.db.CountInstanceStatuses(ctx, host)
if err == nil {
mi.Stats["status_count"] = statusCount
}
domainCount, err := c.db.CountInstanceDomains(ctx, host)
if err == nil {
mi.Stats["domain_count"] = domainCount
}
mi.Registrations = config.GetAccountsRegistrationOpen()
mi.ApprovalRequired = config.GetAccountsApprovalRequired()
mi.InvitesEnabled = false // TODO
mi.MaxTootChars = uint(config.GetStatusesMaxChars())
mi.URLS = &apimodel.InstanceURLs{
StreamingAPI: "wss://" + host,
}
mi.Version = config.GetSoftwareVersion()
// todo: remove hardcoded values and put them in config somewhere
mi.Configuration = &apimodel.InstanceConfiguration{
Statuses: &apimodel.InstanceConfigurationStatuses{
MaxCharacters: config.GetStatusesMaxChars(),
MaxMediaAttachments: config.GetStatusesMediaMaxFiles(),
CharactersReservedPerURL: instanceStatusesCharactersReservedPerURL,
},
MediaAttachments: &apimodel.InstanceConfigurationMediaAttachments{
SupportedMimeTypes: media.SupportedMIMETypes,
ImageSizeLimit: int(config.GetMediaImageMaxSize()), // bytes
ImageMatrixLimit: instanceMediaAttachmentsImageMatrixLimit, // height*width
VideoSizeLimit: int(config.GetMediaVideoMaxSize()), // bytes
VideoFrameRateLimit: instanceMediaAttachmentsVideoFrameRateLimit,
VideoMatrixLimit: instanceMediaAttachmentsVideoMatrixLimit, // height*width
},
Polls: &apimodel.InstanceConfigurationPolls{
MaxOptions: config.GetStatusesPollMaxOptions(),
MaxCharactersPerOption: config.GetStatusesPollOptionMaxChars(),
MinExpiration: instancePollsMinExpiration, // seconds
MaxExpiration: instancePollsMaxExpiration, // seconds
},
Accounts: &apimodel.InstanceConfigurationAccounts{
AllowCustomCSS: config.GetAccountsAllowCustomCSS(),
},
Emojis: &apimodel.InstanceConfigurationEmojis{
EmojiSizeLimit: int(config.GetMediaEmojiLocalMaxSize()), // bytes
},
}
} }
// contact account is optional but let's try to get it // contact account
if i.ContactAccountID != "" { if i.ContactAccountID != "" {
if i.ContactAccount == nil { if i.ContactAccount == nil {
contactAccount, err := c.db.GetAccountByID(ctx, i.ContactAccountID) contactAccount, err := c.db.GetAccountByID(ctx, i.ContactAccountID)
if err == nil { if err != nil {
i.ContactAccount = contactAccount return nil, fmt.Errorf("InstanceToAPIV1Instance: db error getting instance contact account %s: %w", i.ContactAccountID, err)
} }
i.ContactAccount = contactAccount
} }
ma, err := c.AccountToAPIAccountPublic(ctx, i.ContactAccount)
if err == nil { account, err := c.AccountToAPIAccountPublic(ctx, i.ContactAccount)
mi.ContactAccount = ma if err != nil {
return nil, fmt.Errorf("InstanceToAPIV1Instance: error converting instance contact account %s: %w", i.ContactAccountID, err)
} }
instance.ContactAccount = account
} }
return mi, nil return instance, nil
}
func (c *converter) InstanceToAPIV2Instance(ctx context.Context, i *gtsmodel.Instance) (*apimodel.InstanceV2, error) {
instance := &apimodel.InstanceV2{
Domain: i.Domain,
AccountDomain: config.GetAccountDomain(),
Title: i.Title,
Version: config.GetSoftwareVersion(),
SourceURL: instanceSourceURL,
Description: i.Description,
Usage: apimodel.InstanceV2Usage{}, // todo: not implemented
Languages: []string{}, // todo: not implemented
Rules: []interface{}{}, // todo: not implemented
}
// thumbnail
thumbnail := apimodel.InstanceV2Thumbnail{}
iAccount, err := c.db.GetInstanceAccount(ctx, "")
if err != nil {
return nil, fmt.Errorf("InstanceToAPIV2Instance: db error getting instance account: %w", err)
}
if iAccount.AvatarMediaAttachmentID != "" {
if iAccount.AvatarMediaAttachment == nil {
avi, err := c.db.GetAttachmentByID(ctx, iAccount.AvatarMediaAttachmentID)
if err != nil {
return nil, fmt.Errorf("InstanceToAPIV2Instance: error getting instance avatar attachment with id %s: %w", iAccount.AvatarMediaAttachmentID, err)
}
iAccount.AvatarMediaAttachment = avi
}
thumbnail.URL = iAccount.AvatarMediaAttachment.URL
thumbnail.Type = iAccount.AvatarMediaAttachment.File.ContentType
thumbnail.Description = iAccount.AvatarMediaAttachment.Description
thumbnail.Blurhash = iAccount.AvatarMediaAttachment.Blurhash
} else {
thumbnail.URL = config.GetProtocol() + "://" + i.Domain + "/assets/logo.png" // default thumb
}
instance.Thumbnail = thumbnail
// configuration
instance.Configuration.URLs.Streaming = "wss://" + i.Domain
instance.Configuration.Statuses.MaxCharacters = config.GetStatusesMaxChars()
instance.Configuration.Statuses.MaxMediaAttachments = config.GetStatusesMediaMaxFiles()
instance.Configuration.Statuses.CharactersReservedPerURL = instanceStatusesCharactersReservedPerURL
instance.Configuration.MediaAttachments.SupportedMimeTypes = media.SupportedMIMETypes
instance.Configuration.MediaAttachments.ImageSizeLimit = int(config.GetMediaImageMaxSize())
instance.Configuration.MediaAttachments.ImageMatrixLimit = instanceMediaAttachmentsImageMatrixLimit
instance.Configuration.MediaAttachments.VideoSizeLimit = int(config.GetMediaVideoMaxSize())
instance.Configuration.MediaAttachments.VideoFrameRateLimit = instanceMediaAttachmentsVideoFrameRateLimit
instance.Configuration.MediaAttachments.VideoMatrixLimit = instanceMediaAttachmentsVideoMatrixLimit
instance.Configuration.Polls.MaxOptions = config.GetStatusesPollMaxOptions()
instance.Configuration.Polls.MaxCharactersPerOption = config.GetStatusesPollOptionMaxChars()
instance.Configuration.Polls.MinExpiration = instancePollsMinExpiration
instance.Configuration.Polls.MaxExpiration = instancePollsMaxExpiration
instance.Configuration.Accounts.AllowCustomCSS = config.GetAccountsAllowCustomCSS()
instance.Configuration.Accounts.MaxFeaturedTags = instanceAccountsMaxFeaturedTags
instance.Configuration.Emojis.EmojiSizeLimit = int(config.GetMediaEmojiLocalMaxSize())
// registrations
instance.Registrations.Enabled = config.GetAccountsRegistrationOpen()
instance.Registrations.ApprovalRequired = config.GetAccountsApprovalRequired()
instance.Registrations.Message = nil // todo: not implemented
// contact
instance.Contact.Email = i.ContactEmail
if i.ContactAccountID != "" {
if i.ContactAccount == nil {
contactAccount, err := c.db.GetAccountByID(ctx, i.ContactAccountID)
if err != nil {
return nil, fmt.Errorf("InstanceToAPIV2Instance: db error getting instance contact account %s: %w", i.ContactAccountID, err)
}
i.ContactAccount = contactAccount
}
account, err := c.AccountToAPIAccountPublic(ctx, i.ContactAccount)
if err != nil {
return nil, fmt.Errorf("InstanceToAPIV2Instance: error converting instance contact account %s: %w", i.ContactAccountID, err)
}
instance.Contact.Account = account
}
return instance, nil
} }
func (c *converter) RelationshipToAPIRelationship(ctx context.Context, r *gtsmodel.Relationship) (*apimodel.Relationship, error) { func (c *converter) RelationshipToAPIRelationship(ctx context.Context, r *gtsmodel.Relationship) (*apimodel.Relationship, error) {

View file

@ -24,8 +24,9 @@
"testing" "testing"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/testrig"
) )
type InternalToFrontendTestSuite struct { type InternalToFrontendTestSuite struct {
@ -454,93 +455,207 @@ func (suite *InternalToFrontendTestSuite) TestVideoAttachmentToFrontend() {
}`, string(b)) }`, string(b))
} }
func (suite *InternalToFrontendTestSuite) TestInstanceToFrontend() { func (suite *InternalToFrontendTestSuite) TestInstanceV1ToFrontend() {
testInstance := &gtsmodel.Instance{ ctx := context.Background()
CreatedAt: testrig.TimeMustParse("2021-10-20T11:36:45Z"),
UpdatedAt: testrig.TimeMustParse("2021-10-20T11:36:45Z"), i := &gtsmodel.Instance{}
Domain: "example.org", if err := suite.db.GetWhere(ctx, []db.Where{{Key: "domain", Value: config.GetHost()}}, i); err != nil {
Title: "example instance", suite.FailNow(err.Error())
URI: "https://example.org",
ShortDescription: "a little description",
Description: "a much longer description",
ContactEmail: "someone@example.org",
Version: "software-from-hell 0.666",
} }
apiInstance, err := suite.typeconverter.InstanceToAPIInstance(context.Background(), testInstance) instance, err := suite.typeconverter.InstanceToAPIV1Instance(ctx, i)
suite.NoError(err) if err != nil {
suite.FailNow(err.Error())
}
b, err := json.MarshalIndent(apiInstance, "", " ") b, err := json.MarshalIndent(instance, "", " ")
suite.NoError(err) suite.NoError(err)
suite.Equal(`{ suite.Equal(`{
"uri": "https://example.org", "uri": "http://localhost:8080",
"title": "example instance", "account_domain": "localhost:8080",
"description": "a much longer description", "title": "GoToSocial Testrig Instance",
"short_description": "a little description", "description": "\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e",
"email": "someone@example.org", "short_description": "\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e",
"version": "software-from-hell 0.666", "email": "admin@example.org",
"registrations": false, "version": "0.0.0-testrig",
"approval_required": false, "registrations": true,
"approval_required": true,
"invites_enabled": false, "invites_enabled": false,
"thumbnail": "", "configuration": {
"max_toot_chars": 0 "statuses": {
}`, string(b)) "max_characters": 5000,
} "max_media_attachments": 6,
"characters_reserved_per_url": 25
func (suite *InternalToFrontendTestSuite) TestInstanceToFrontendWithAdminAccount() { },
testInstance := &gtsmodel.Instance{ "media_attachments": {
CreatedAt: testrig.TimeMustParse("2021-10-20T11:36:45Z"), "supported_mime_types": [
UpdatedAt: testrig.TimeMustParse("2021-10-20T11:36:45Z"), "image/jpeg",
Domain: "example.org", "image/gif",
Title: "example instance", "image/png",
URI: "https://example.org", "image/webp",
ShortDescription: "a little description", "video/mp4"
Description: "a much longer description", ],
ContactEmail: "someone@example.org", "image_size_limit": 10485760,
ContactAccountID: suite.testAccounts["remote_account_2"].ID, "image_matrix_limit": 16777216,
Version: "software-from-hell 0.666", "video_size_limit": 41943040,
} "video_frame_rate_limit": 60,
"video_matrix_limit": 16777216
apiInstance, err := suite.typeconverter.InstanceToAPIInstance(context.Background(), testInstance) },
suite.NoError(err) "polls": {
"max_options": 6,
b, err := json.MarshalIndent(apiInstance, "", " ") "max_characters_per_option": 50,
suite.NoError(err) "min_expiration": 300,
"max_expiration": 2629746
suite.Equal(`{ },
"uri": "https://example.org", "accounts": {
"title": "example instance", "allow_custom_css": true,
"description": "a much longer description", "max_featured_tags": 10
"short_description": "a little description", },
"email": "someone@example.org", "emojis": {
"version": "software-from-hell 0.666", "emoji_size_limit": 51200
"registrations": false, }
"approval_required": false, },
"invites_enabled": false, "urls": {
"thumbnail": "", "streaming_api": "wss://localhost:8080"
},
"stats": {
"domain_count": 2,
"status_count": 16,
"user_count": 4
},
"thumbnail": "http://localhost:8080/assets/logo.png",
"contact_account": { "contact_account": {
"id": "01FHMQX3GAABWSM0S2VZEC2SWC", "id": "01F8MH17FWEB39HZJ76B6VXSKF",
"username": "Some_User", "username": "admin",
"acct": "Some_User@example.org", "acct": "admin",
"display_name": "some user", "display_name": "",
"locked": true, "locked": false,
"bot": false, "bot": false,
"created_at": "2020-08-10T12:13:28.000Z", "created_at": "2022-05-17T13:10:59.000Z",
"note": "i'm a real son of a gun", "note": "",
"url": "http://example.org/@Some_User", "url": "http://localhost:8080/@admin",
"avatar": "", "avatar": "",
"avatar_static": "", "avatar_static": "",
"header": "http://localhost:8080/assets/default_header.png", "header": "http://localhost:8080/assets/default_header.png",
"header_static": "http://localhost:8080/assets/default_header.png", "header_static": "http://localhost:8080/assets/default_header.png",
"followers_count": 0, "followers_count": 1,
"following_count": 0, "following_count": 1,
"statuses_count": 0, "statuses_count": 4,
"last_status_at": null, "last_status_at": "2021-10-20T10:41:37.000Z",
"emojis": [], "emojis": [],
"fields": [] "fields": [],
"enable_rss": true,
"role": "admin"
}, },
"max_toot_chars": 0 "max_toot_chars": 5000
}`, string(b))
}
func (suite *InternalToFrontendTestSuite) TestInstanceV2ToFrontend() {
ctx := context.Background()
i := &gtsmodel.Instance{}
if err := suite.db.GetWhere(ctx, []db.Where{{Key: "domain", Value: config.GetHost()}}, i); err != nil {
suite.FailNow(err.Error())
}
instance, err := suite.typeconverter.InstanceToAPIV2Instance(ctx, i)
if err != nil {
suite.FailNow(err.Error())
}
b, err := json.MarshalIndent(instance, "", " ")
suite.NoError(err)
suite.Equal(`{
"domain": "localhost:8080",
"account_domain": "localhost:8080",
"title": "GoToSocial Testrig Instance",
"version": "0.0.0-testrig",
"source_url": "https://github.com/superseriousbusiness/gotosocial",
"description": "\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e",
"usage": {
"users": {
"active_month": 0
}
},
"thumbnail": {
"url": "http://localhost:8080/assets/logo.png"
},
"languages": [],
"configuration": {
"urls": {
"streaming": "wss://localhost:8080"
},
"accounts": {
"allow_custom_css": true,
"max_featured_tags": 10
},
"statuses": {
"max_characters": 5000,
"max_media_attachments": 6,
"characters_reserved_per_url": 25
},
"media_attachments": {
"supported_mime_types": [
"image/jpeg",
"image/gif",
"image/png",
"image/webp",
"video/mp4"
],
"image_size_limit": 10485760,
"image_matrix_limit": 16777216,
"video_size_limit": 41943040,
"video_frame_rate_limit": 60,
"video_matrix_limit": 16777216
},
"polls": {
"max_options": 6,
"max_characters_per_option": 50,
"min_expiration": 300,
"max_expiration": 2629746
},
"translation": {
"enabled": false
},
"emojis": {
"emoji_size_limit": 51200
}
},
"registrations": {
"enabled": true,
"approval_required": true,
"message": null
},
"contact": {
"email": "admin@example.org",
"account": {
"id": "01F8MH17FWEB39HZJ76B6VXSKF",
"username": "admin",
"acct": "admin",
"display_name": "",
"locked": false,
"bot": false,
"created_at": "2022-05-17T13:10:59.000Z",
"note": "",
"url": "http://localhost:8080/@admin",
"avatar": "",
"avatar_static": "",
"header": "http://localhost:8080/assets/default_header.png",
"header_static": "http://localhost:8080/assets/default_header.png",
"followers_count": 1,
"following_count": 1,
"statuses_count": 4,
"last_status_at": "2021-10-20T10:41:37.000Z",
"emojis": [],
"fields": [],
"enable_rss": true,
"role": "admin"
}
},
"rules": []
}`, string(b)) }`, string(b))
} }

Some files were not shown because too many files have changed in this diff Show more