mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-27 01:33:32 -06:00
fmt + lint
This commit is contained in:
parent
d68c64505b
commit
a602a3d9d2
21 changed files with 51 additions and 22 deletions
|
|
@ -42,7 +42,7 @@ func (m *Module) TokenPOSTHandler(c *gin.Context) {
|
||||||
|
|
||||||
form := &tokenBody{}
|
form := &tokenBody{}
|
||||||
if err := c.ShouldBind(form); err == nil {
|
if err := c.ShouldBind(form); err == nil {
|
||||||
c.Request.Form = url.Values{}
|
c.Request.Form = url.Values{}
|
||||||
if form.ClientID != nil {
|
if form.ClientID != nil {
|
||||||
c.Request.Form.Set("client_id", *form.ClientID)
|
c.Request.Form.Set("client_id", *form.ClientID)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// FollowRequestAcceptPOSTHandler deals with follow request accepting. It should be served at
|
||||||
|
// /api/v1/follow_requests/:id/authorize
|
||||||
func (m *Module) FollowRequestAcceptPOSTHandler(c *gin.Context) {
|
func (m *Module) FollowRequestAcceptPOSTHandler(c *gin.Context) {
|
||||||
l := m.log.WithField("func", "statusCreatePOSTHandler")
|
l := m.log.WithField("func", "statusCreatePOSTHandler")
|
||||||
authed, err := oauth.Authed(c, true, true, true, true)
|
authed, err := oauth.Authed(c, true, true, true, true)
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ package followrequest
|
||||||
|
|
||||||
import "github.com/gin-gonic/gin"
|
import "github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
// FollowRequestDenyPOSTHandler deals with follow request rejection. It should be served at
|
||||||
|
// /api/v1/follow_requests/:id/reject
|
||||||
func (m *Module) FollowRequestDenyPOSTHandler(c *gin.Context) {
|
func (m *Module) FollowRequestDenyPOSTHandler(c *gin.Context) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// FollowRequestGETHandler allows clients to get a list of their incoming follow requests.
|
||||||
func (m *Module) FollowRequestGETHandler(c *gin.Context) {
|
func (m *Module) FollowRequestGETHandler(c *gin.Context) {
|
||||||
l := m.log.WithField("func", "statusCreatePOSTHandler")
|
l := m.log.WithField("func", "statusCreatePOSTHandler")
|
||||||
authed, err := oauth.Authed(c, true, true, true, true)
|
authed, err := oauth.Authed(c, true, true, true, true)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// InstanceInformationPath
|
// InstanceInformationPath is for serving instance info requests
|
||||||
InstanceInformationPath = "api/v1/instance"
|
InstanceInformationPath = "api/v1/instance"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// InstanceInformationGETHandler is for serving instance information at /api/v1/instance
|
||||||
func (m *Module) InstanceInformationGETHandler(c *gin.Context) {
|
func (m *Module) InstanceInformationGETHandler(c *gin.Context) {
|
||||||
l := m.log.WithField("func", "InstanceInformationGETHandler")
|
l := m.log.WithField("func", "InstanceInformationGETHandler")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,10 @@ import (
|
||||||
|
|
||||||
// BasePath is the base API path for making media requests
|
// BasePath is the base API path for making media requests
|
||||||
const BasePath = "/api/v1/media"
|
const BasePath = "/api/v1/media"
|
||||||
|
|
||||||
// IDKey is the key for media attachment IDs
|
// IDKey is the key for media attachment IDs
|
||||||
const IDKey = "id"
|
const IDKey = "id"
|
||||||
|
|
||||||
// BasePathWithID corresponds to a media attachment with the given ID
|
// BasePathWithID corresponds to a media attachment with the given ID
|
||||||
const BasePathWithID = BasePath + "/:" + IDKey
|
const BasePathWithID = BasePath + "/:" + IDKey
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ func (m *Module) MediaGETHandler(c *gin.Context) {
|
||||||
|
|
||||||
attachment, errWithCode := m.processor.MediaGet(authed, attachmentID)
|
attachment, errWithCode := m.processor.MediaGet(authed, attachmentID)
|
||||||
if errWithCode != nil {
|
if errWithCode != nil {
|
||||||
c.JSON(errWithCode.Code(),gin.H{"error": errWithCode.Safe()})
|
c.JSON(errWithCode.Code(), gin.H{"error": errWithCode.Safe()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,11 @@ type AttachmentRequest struct {
|
||||||
Focus string `form:"focus"`
|
Focus string `form:"focus"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// AttachmentRequest represents the form data parameters submitted by a client during a media update/PUT request.
|
// AttachmentUpdateRequest represents the form data parameters submitted by a client during a media update/PUT request.
|
||||||
// See: https://docs.joinmastodon.org/methods/statuses/media/
|
// See: https://docs.joinmastodon.org/methods/statuses/media/
|
||||||
type AttachmentUpdateRequest struct {
|
type AttachmentUpdateRequest struct {
|
||||||
Description *string `form:"description" json:"description" xml:"description"`
|
Description *string `form:"description" json:"description" xml:"description"`
|
||||||
Focus *string `form:"focus" json:"focus" xml:"focus"`
|
Focus *string `form:"focus" json:"focus" xml:"focus"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attachment represents the object returned to a client after a successful media upload request.
|
// Attachment represents the object returned to a client after a successful media upload request.
|
||||||
|
|
|
||||||
|
|
@ -119,11 +119,15 @@ const (
|
||||||
VisibilityDirect Visibility = "direct"
|
VisibilityDirect Visibility = "direct"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AdvancedStatusCreateForm wraps the mastodon status create form along with the GTS advanced
|
||||||
|
// visibility settings.
|
||||||
type AdvancedStatusCreateForm struct {
|
type AdvancedStatusCreateForm struct {
|
||||||
StatusCreateRequest
|
StatusCreateRequest
|
||||||
AdvancedVisibilityFlagsForm
|
AdvancedVisibilityFlagsForm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AdvancedVisibilityFlagsForm allows a few more advanced flags to be set on new statuses, in addition
|
||||||
|
// to the standard mastodon-compatible ones.
|
||||||
type AdvancedVisibilityFlagsForm struct {
|
type AdvancedVisibilityFlagsForm struct {
|
||||||
// The gotosocial visibility model
|
// The gotosocial visibility model
|
||||||
VisibilityAdvanced *string `form:"visibility_advanced"`
|
VisibilityAdvanced *string `form:"visibility_advanced"`
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/message"
|
"github.com/superseriousbusiness/gotosocial/internal/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// InboxPOSTHandler deals with incoming POST requests to an actor's inbox.
|
||||||
|
// Eg., POST to https://example.org/users/whatever/inbox.
|
||||||
func (m *Module) InboxPOSTHandler(c *gin.Context) {
|
func (m *Module) InboxPOSTHandler(c *gin.Context) {
|
||||||
l := m.log.WithFields(logrus.Fields{
|
l := m.log.WithFields(logrus.Fields{
|
||||||
"func": "InboxPOSTHandler",
|
"func": "InboxPOSTHandler",
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,8 @@ const (
|
||||||
// Use this anywhere you need to know the username of the user being queried.
|
// Use this anywhere you need to know the username of the user being queried.
|
||||||
// Eg https://example.org/users/:username
|
// Eg https://example.org/users/:username
|
||||||
UsersBasePathWithUsername = UsersBasePath + "/:" + UsernameKey
|
UsersBasePathWithUsername = UsersBasePath + "/:" + UsernameKey
|
||||||
UsersInboxPath = UsersBasePathWithUsername + "/" + util.InboxPath
|
// UsersInboxPath is for serving POST requests to a user's inbox with the given username key.
|
||||||
|
UsersInboxPath = UsersBasePathWithUsername + "/" + util.InboxPath
|
||||||
)
|
)
|
||||||
|
|
||||||
// ActivityPubAcceptHeaders represents the Accept headers mentioned here:
|
// ActivityPubAcceptHeaders represents the Accept headers mentioned here:
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// The base path for serving webfinger lookup requests
|
// WebfingerBasePath is the base path for serving webfinger lookup requests
|
||||||
WebfingerBasePath = ".well-known/webfinger"
|
WebfingerBasePath = ".well-known/webfinger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,10 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DBTypePostgres string = "POSTGRES"
|
const (
|
||||||
|
// DBTypePostgres represents an underlying POSTGRES database type.
|
||||||
|
DBTypePostgres string = "POSTGRES"
|
||||||
|
)
|
||||||
|
|
||||||
// ErrNoEntries is to be returned from the DB interface when no entries are found for a given query.
|
// ErrNoEntries is to be returned from the DB interface when no entries are found for a given query.
|
||||||
type ErrNoEntries struct{}
|
type ErrNoEntries struct{}
|
||||||
|
|
@ -112,6 +115,8 @@ type DB interface {
|
||||||
HANDY SHORTCUTS
|
HANDY SHORTCUTS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// AcceptFollowRequest moves a follow request in the database from the follow_requests table to the follows table.
|
||||||
|
// In other words, it should create the follow, and delete the existing follow request.
|
||||||
AcceptFollowRequest(originAccountID string, targetAccountID string) error
|
AcceptFollowRequest(originAccountID string, targetAccountID string) error
|
||||||
|
|
||||||
// CreateInstanceAccount creates an account in the database with the same username as the instance host value.
|
// CreateInstanceAccount creates an account in the database with the same username as the instance host value.
|
||||||
|
|
@ -150,6 +155,9 @@ type DB interface {
|
||||||
// In case of no entries, a 'no entries' error will be returned
|
// In case of no entries, a 'no entries' error will be returned
|
||||||
GetFollowersByAccountID(accountID string, followers *[]gtsmodel.Follow) error
|
GetFollowersByAccountID(accountID string, followers *[]gtsmodel.Follow) error
|
||||||
|
|
||||||
|
// GetFavesByAccountID is a shortcut for the common action of fetching a list of faves made by the given accountID.
|
||||||
|
// The given slice 'faves' will be set to the result of the query, whatever it is.
|
||||||
|
// In case of no entries, a 'no entries' error will be returned
|
||||||
GetFavesByAccountID(accountID string, faves *[]gtsmodel.StatusFave) error
|
GetFavesByAccountID(accountID string, faves *[]gtsmodel.StatusFave) error
|
||||||
|
|
||||||
// GetStatusesByAccountID is a shortcut for the common action of fetching a list of statuses produced by accountID.
|
// GetStatusesByAccountID is a shortcut for the common action of fetching a list of statuses produced by accountID.
|
||||||
|
|
|
||||||
|
|
@ -317,9 +317,9 @@ func (ps *postgresService) AcceptFollowRequest(originAccountID string, targetAcc
|
||||||
}
|
}
|
||||||
|
|
||||||
follow := >smodel.Follow{
|
follow := >smodel.Follow{
|
||||||
AccountID: originAccountID,
|
AccountID: originAccountID,
|
||||||
TargetAccountID: targetAccountID,
|
TargetAccountID: targetAccountID,
|
||||||
URI: fr.URI,
|
URI: fr.URI,
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := ps.conn.Model(follow).Insert(); err != nil {
|
if _, err := ps.conn.Model(follow).Insert(); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ func (c *Clock) Now() time.Time {
|
||||||
return time.Now()
|
return time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewClock returns a simple pub.Clock for use in federation interfaces.
|
||||||
func NewClock() pub.Clock {
|
func NewClock() pub.Clock {
|
||||||
return &Clock{}
|
return &Clock{}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ type federatingDB struct {
|
||||||
typeConverter typeutils.TypeConverter
|
typeConverter typeutils.TypeConverter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewFederatingDB returns a pub.Database interface using the given database, config, and logger.
|
||||||
func NewFederatingDB(db db.DB, config *config.Config, log *logrus.Logger) pub.Database {
|
func NewFederatingDB(db db.DB, config *config.Config, log *logrus.Logger) pub.Database {
|
||||||
return &federatingDB{
|
return &federatingDB{
|
||||||
locks: new(sync.Map),
|
locks: new(sync.Map),
|
||||||
|
|
@ -505,8 +506,8 @@ func (f *federatingDB) NewID(c context.Context, t vocab.Type) (id *url.URL, err
|
||||||
func (f *federatingDB) Followers(c context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error) {
|
func (f *federatingDB) Followers(c context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error) {
|
||||||
l := f.log.WithFields(
|
l := f.log.WithFields(
|
||||||
logrus.Fields{
|
logrus.Fields{
|
||||||
"func": "Followers",
|
"func": "Followers",
|
||||||
"actorIRI": actorIRI.String(),
|
"actorIRI": actorIRI.String(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
l.Debugf("entering FOLLOWERS function with actorIRI %s", actorIRI.String())
|
l.Debugf("entering FOLLOWERS function with actorIRI %s", actorIRI.String())
|
||||||
|
|
@ -547,8 +548,8 @@ func (f *federatingDB) Followers(c context.Context, actorIRI *url.URL) (follower
|
||||||
func (f *federatingDB) Following(c context.Context, actorIRI *url.URL) (following vocab.ActivityStreamsCollection, err error) {
|
func (f *federatingDB) Following(c context.Context, actorIRI *url.URL) (following vocab.ActivityStreamsCollection, err error) {
|
||||||
l := f.log.WithFields(
|
l := f.log.WithFields(
|
||||||
logrus.Fields{
|
logrus.Fields{
|
||||||
"func": "Following",
|
"func": "Following",
|
||||||
"actorIRI": actorIRI.String(),
|
"actorIRI": actorIRI.String(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
l.Debugf("entering FOLLOWING function with actorIRI %s", actorIRI.String())
|
l.Debugf("entering FOLLOWING function with actorIRI %s", actorIRI.String())
|
||||||
|
|
@ -589,8 +590,8 @@ func (f *federatingDB) Following(c context.Context, actorIRI *url.URL) (followin
|
||||||
func (f *federatingDB) Liked(c context.Context, actorIRI *url.URL) (liked vocab.ActivityStreamsCollection, err error) {
|
func (f *federatingDB) Liked(c context.Context, actorIRI *url.URL) (liked vocab.ActivityStreamsCollection, err error) {
|
||||||
l := f.log.WithFields(
|
l := f.log.WithFields(
|
||||||
logrus.Fields{
|
logrus.Fields{
|
||||||
"func": "Liked",
|
"func": "Liked",
|
||||||
"actorIRI": actorIRI.String(),
|
"actorIRI": actorIRI.String(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
l.Debugf("entering LIKED function with actorIRI %s", actorIRI.String())
|
l.Debugf("entering LIKED function with actorIRI %s", actorIRI.String())
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,7 @@ type Mentionable interface {
|
||||||
withHref
|
withHref
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Followable represents the minimum interface for an activitystreams 'follow' activity.
|
||||||
type Followable interface {
|
type Followable interface {
|
||||||
withJSONLDId
|
withJSONLDId
|
||||||
withTypeName
|
withTypeName
|
||||||
|
|
|
||||||
|
|
@ -333,8 +333,8 @@ func (c *converter) ASFollowToFollowRequest(followable Followable) (*gtsmodel.Fo
|
||||||
}
|
}
|
||||||
|
|
||||||
followRequest := >smodel.FollowRequest{
|
followRequest := >smodel.FollowRequest{
|
||||||
URI: uri,
|
URI: uri,
|
||||||
AccountID: originAccount.ID,
|
AccountID: originAccount.ID,
|
||||||
TargetAccountID: targetAccount.ID,
|
TargetAccountID: targetAccount.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/transport"
|
"github.com/superseriousbusiness/gotosocial/internal/transport"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewTestFederator returns a federator with the given database and (mock!!) transport controller.
|
||||||
func NewTestFederator(db db.DB, tc transport.Controller) federation.Federator {
|
func NewTestFederator(db db.DB, tc transport.Controller) federation.Federator {
|
||||||
return federation.NewFederator(db, tc, NewTestConfig(), NewTestLog(), NewTestTypeConverter(db))
|
return federation.NewFederator(db, tc, NewTestConfig(), NewTestLog(), NewTestTypeConverter(db))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1037,6 +1037,7 @@ func NewTestFaves() map[string]*gtsmodel.StatusFave {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ActivityWithSignature wraps a pub.Activity along with its signature headers, for testing.
|
||||||
type ActivityWithSignature struct {
|
type ActivityWithSignature struct {
|
||||||
Activity pub.Activity
|
Activity pub.Activity
|
||||||
SignatureHeader string
|
SignatureHeader string
|
||||||
|
|
@ -1076,11 +1077,11 @@ func NewTestActivities(accounts map[string]*gtsmodel.Account) map[string]Activit
|
||||||
|
|
||||||
// NewTestFediPeople returns a bunch of activity pub Person representations for testing converters and so on.
|
// NewTestFediPeople returns a bunch of activity pub Person representations for testing converters and so on.
|
||||||
func NewTestFediPeople() map[string]typeutils.Accountable {
|
func NewTestFediPeople() map[string]typeutils.Accountable {
|
||||||
new_person_1priv, err := rsa.GenerateKey(rand.Reader, 2048)
|
newPerson1Priv, err := rsa.GenerateKey(rand.Reader, 2048)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
new_person_1pub := &new_person_1priv.PublicKey
|
newPerson1Pub := &newPerson1Priv.PublicKey
|
||||||
|
|
||||||
return map[string]typeutils.Accountable{
|
return map[string]typeutils.Accountable{
|
||||||
"new_person_1": newPerson(
|
"new_person_1": newPerson(
|
||||||
|
|
@ -1096,7 +1097,7 @@ func NewTestFediPeople() map[string]typeutils.Accountable {
|
||||||
URLMustParse("https://unknown-instance.com/@brand_new_person"),
|
URLMustParse("https://unknown-instance.com/@brand_new_person"),
|
||||||
true,
|
true,
|
||||||
URLMustParse("https://unknown-instance.com/users/brand_new_person#main-key"),
|
URLMustParse("https://unknown-instance.com/users/brand_new_person#main-key"),
|
||||||
new_person_1pub,
|
newPerson1Pub,
|
||||||
URLMustParse("https://unknown-instance.com/media/some_avatar_filename.jpeg"),
|
URLMustParse("https://unknown-instance.com/media/some_avatar_filename.jpeg"),
|
||||||
"image/jpeg",
|
"image/jpeg",
|
||||||
URLMustParse("https://unknown-instance.com/media/some_header_filename.jpeg"),
|
URLMustParse("https://unknown-instance.com/media/some_header_filename.jpeg"),
|
||||||
|
|
@ -1105,6 +1106,7 @@ func NewTestFediPeople() map[string]typeutils.Accountable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTestDereferenceRequests returns a map of incoming dereference requests, with their signatures.
|
||||||
func NewTestDereferenceRequests(accounts map[string]*gtsmodel.Account) map[string]ActivityWithSignature {
|
func NewTestDereferenceRequests(accounts map[string]*gtsmodel.Account) map[string]ActivityWithSignature {
|
||||||
sig, digest, date := getSignatureForDereference(accounts["remote_account_1"].PublicKeyURI, accounts["remote_account_1"].PrivateKey, URLMustParse(accounts["local_account_1"].URI))
|
sig, digest, date := getSignatureForDereference(accounts["remote_account_1"].PublicKeyURI, accounts["remote_account_1"].PrivateKey, URLMustParse(accounts["local_account_1"].URI))
|
||||||
return map[string]ActivityWithSignature{
|
return map[string]ActivityWithSignature{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue