fmt + lint

This commit is contained in:
tsmethurst 2021-05-15 11:53:38 +02:00
parent d68c64505b
commit a602a3d9d2
21 changed files with 51 additions and 22 deletions

View File

@ -42,7 +42,7 @@ func (m *Module) TokenPOSTHandler(c *gin.Context) {
form := &tokenBody{}
if err := c.ShouldBind(form); err == nil {
c.Request.Form = url.Values{}
c.Request.Form = url.Values{}
if form.ClientID != nil {
c.Request.Form.Set("client_id", *form.ClientID)
}

View File

@ -25,6 +25,8 @@ import (
"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) {
l := m.log.WithField("func", "statusCreatePOSTHandler")
authed, err := oauth.Authed(c, true, true, true, true)

View File

@ -20,6 +20,8 @@ package followrequest
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) {
}

View File

@ -25,6 +25,7 @@ import (
"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) {
l := m.log.WithField("func", "statusCreatePOSTHandler")
authed, err := oauth.Authed(c, true, true, true, true)

View File

@ -11,7 +11,7 @@ import (
)
const (
// InstanceInformationPath
// InstanceInformationPath is for serving instance info requests
InstanceInformationPath = "api/v1/instance"
)

View File

@ -6,6 +6,7 @@ import (
"github.com/gin-gonic/gin"
)
// InstanceInformationGETHandler is for serving instance information at /api/v1/instance
func (m *Module) InstanceInformationGETHandler(c *gin.Context) {
l := m.log.WithField("func", "InstanceInformationGETHandler")

View File

@ -33,8 +33,10 @@ import (
// BasePath is the base API path for making media requests
const BasePath = "/api/v1/media"
// IDKey is the key for media attachment IDs
const IDKey = "id"
// BasePathWithID corresponds to a media attachment with the given ID
const BasePathWithID = BasePath + "/:" + IDKey

View File

@ -43,7 +43,7 @@ func (m *Module) MediaGETHandler(c *gin.Context) {
attachment, errWithCode := m.processor.MediaGet(authed, attachmentID)
if errWithCode != nil {
c.JSON(errWithCode.Code(),gin.H{"error": errWithCode.Safe()})
c.JSON(errWithCode.Code(), gin.H{"error": errWithCode.Safe()})
return
}

View File

@ -28,11 +28,11 @@ type AttachmentRequest struct {
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/
type AttachmentUpdateRequest struct {
Description *string `form:"description" json:"description" xml:"description"`
Focus *string `form:"focus" json:"focus" xml:"focus"`
Description *string `form:"description" json:"description" xml:"description"`
Focus *string `form:"focus" json:"focus" xml:"focus"`
}
// Attachment represents the object returned to a client after a successful media upload request.

View File

@ -119,11 +119,15 @@ const (
VisibilityDirect Visibility = "direct"
)
// AdvancedStatusCreateForm wraps the mastodon status create form along with the GTS advanced
// visibility settings.
type AdvancedStatusCreateForm struct {
StatusCreateRequest
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 {
// The gotosocial visibility model
VisibilityAdvanced *string `form:"visibility_advanced"`

View File

@ -26,6 +26,8 @@ import (
"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) {
l := m.log.WithFields(logrus.Fields{
"func": "InboxPOSTHandler",

View File

@ -38,7 +38,8 @@ const (
// Use this anywhere you need to know the username of the user being queried.
// Eg https://example.org/users/:username
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:

View File

@ -29,7 +29,7 @@ import (
)
const (
// The base path for serving webfinger lookup requests
// WebfingerBasePath is the base path for serving webfinger lookup requests
WebfingerBasePath = ".well-known/webfinger"
)

View File

@ -26,7 +26,10 @@ import (
"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.
type ErrNoEntries struct{}
@ -112,6 +115,8 @@ type DB interface {
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
// 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
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
// GetStatusesByAccountID is a shortcut for the common action of fetching a list of statuses produced by accountID.

View File

@ -317,9 +317,9 @@ func (ps *postgresService) AcceptFollowRequest(originAccountID string, targetAcc
}
follow := &gtsmodel.Follow{
AccountID: originAccountID,
AccountID: originAccountID,
TargetAccountID: targetAccountID,
URI: fr.URI,
URI: fr.URI,
}
if _, err := ps.conn.Model(follow).Insert(); err != nil {

View File

@ -37,6 +37,7 @@ func (c *Clock) Now() time.Time {
return time.Now()
}
// NewClock returns a simple pub.Clock for use in federation interfaces.
func NewClock() pub.Clock {
return &Clock{}
}

View File

@ -47,6 +47,7 @@ type federatingDB struct {
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 {
return &federatingDB{
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) {
l := f.log.WithFields(
logrus.Fields{
"func": "Followers",
"actorIRI": actorIRI.String(),
"func": "Followers",
"actorIRI": 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) {
l := f.log.WithFields(
logrus.Fields{
"func": "Following",
"actorIRI": actorIRI.String(),
"func": "Following",
"actorIRI": 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) {
l := f.log.WithFields(
logrus.Fields{
"func": "Liked",
"actorIRI": actorIRI.String(),
"func": "Liked",
"actorIRI": actorIRI.String(),
},
)
l.Debugf("entering LIKED function with actorIRI %s", actorIRI.String())

View File

@ -95,6 +95,7 @@ type Mentionable interface {
withHref
}
// Followable represents the minimum interface for an activitystreams 'follow' activity.
type Followable interface {
withJSONLDId
withTypeName

View File

@ -333,8 +333,8 @@ func (c *converter) ASFollowToFollowRequest(followable Followable) (*gtsmodel.Fo
}
followRequest := &gtsmodel.FollowRequest{
URI: uri,
AccountID: originAccount.ID,
URI: uri,
AccountID: originAccount.ID,
TargetAccountID: targetAccount.ID,
}

View File

@ -24,6 +24,7 @@ import (
"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 {
return federation.NewFederator(db, tc, NewTestConfig(), NewTestLog(), NewTestTypeConverter(db))
}

View File

@ -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 {
Activity pub.Activity
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.
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 {
panic(err)
}
new_person_1pub := &new_person_1priv.PublicKey
newPerson1Pub := &newPerson1Priv.PublicKey
return map[string]typeutils.Accountable{
"new_person_1": newPerson(
@ -1096,7 +1097,7 @@ func NewTestFediPeople() map[string]typeutils.Accountable {
URLMustParse("https://unknown-instance.com/@brand_new_person"),
true,
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"),
"image/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 {
sig, digest, date := getSignatureForDereference(accounts["remote_account_1"].PublicKeyURI, accounts["remote_account_1"].PrivateKey, URLMustParse(accounts["local_account_1"].URI))
return map[string]ActivityWithSignature{