diff options
Diffstat (limited to 'internal')
62 files changed, 255 insertions, 629 deletions
diff --git a/internal/action/mock_GTSAction.go b/internal/action/mock_GTSAction.go deleted file mode 100644 index dbc83755f..000000000 --- a/internal/action/mock_GTSAction.go +++ /dev/null @@ -1,32 +0,0 @@ -// Code generated by mockery v2.7.4. DO NOT EDIT. - -package action - -import ( - context "context" - - config "github.com/superseriousbusiness/gotosocial/internal/config" - - logrus "github.com/sirupsen/logrus" - - mock "github.com/stretchr/testify/mock" -) - -// MockGTSAction is an autogenerated mock type for the GTSAction type -type MockGTSAction struct { - mock.Mock -} - -// Execute provides a mock function with given fields: _a0, _a1, _a2 -func (_m *MockGTSAction) Execute(_a0 context.Context, _a1 *config.Config, _a2 *logrus.Logger) error { - ret := _m.Called(_a0, _a1, _a2) - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *config.Config, *logrus.Logger) error); ok { - r0 = rf(_a0, _a1, _a2) - } else { - r0 = ret.Error(0) - } - - return r0 -} diff --git a/internal/api/client/account/account.go b/internal/api/client/account/account.go index 94f753825..3a820c0ea 100644 --- a/internal/api/client/account/account.go +++ b/internal/api/client/account/account.go @@ -26,7 +26,7 @@ import ( "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" - "github.com/superseriousbusiness/gotosocial/internal/message" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/router" ) @@ -61,7 +61,7 @@ const ( GetFollowingPath = BasePathWithID + "/following" // GetRelationshipsPath is for showing an account's relationship with other accounts GetRelationshipsPath = BasePath + "/relationships" - // FollowPath is for POSTing new follows to, and updating existing follows + // PostFollowPath is for POSTing new follows to, and updating existing follows PostFollowPath = BasePathWithID + "/follow" // PostUnfollowPath is for POSTing an unfollow PostUnfollowPath = BasePathWithID + "/unfollow" @@ -70,12 +70,12 @@ const ( // Module implements the ClientAPIModule interface for account-related actions type Module struct { config *config.Config - processor message.Processor + processor processing.Processor log *logrus.Logger } // New returns a new account module -func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { return &Module{ config: config, processor: processor, diff --git a/internal/api/client/account/account_test.go b/internal/api/client/account/account_test.go index d0560bcb6..5e1959cc2 100644 --- a/internal/api/client/account/account_test.go +++ b/internal/api/client/account/account_test.go @@ -4,13 +4,13 @@ import ( "github.com/sirupsen/logrus" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/api/client/account" + "github.com/superseriousbusiness/gotosocial/internal/blob" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/federation" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" - "github.com/superseriousbusiness/gotosocial/internal/message" "github.com/superseriousbusiness/gotosocial/internal/oauth" - "github.com/superseriousbusiness/gotosocial/internal/storage" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/typeutils" ) @@ -22,9 +22,9 @@ type AccountStandardTestSuite struct { db db.DB log *logrus.Logger tc typeutils.TypeConverter - storage storage.Storage + storage blob.Storage federator federation.Federator - processor message.Processor + processor processing.Processor // standard suite models testTokens map[string]*oauth.Token diff --git a/internal/api/client/account/following.go b/internal/api/client/account/following.go index 2a1373e40..f1adeac2b 100644 --- a/internal/api/client/account/following.go +++ b/internal/api/client/account/following.go @@ -25,7 +25,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/oauth" ) -// AccountFollowersGETHandler serves the followers of the requested account, if they're visible to the requester. +// AccountFollowingGETHandler serves the following of the requested account, if they're visible to the requester. func (m *Module) AccountFollowingGETHandler(c *gin.Context) { authed, err := oauth.Authed(c, true, true, true, true) if err != nil { diff --git a/internal/api/client/admin/admin.go b/internal/api/client/admin/admin.go index 7ce5311eb..b33813a7d 100644 --- a/internal/api/client/admin/admin.go +++ b/internal/api/client/admin/admin.go @@ -24,7 +24,7 @@ import ( "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" - "github.com/superseriousbusiness/gotosocial/internal/message" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/router" ) @@ -38,12 +38,12 @@ const ( // Module implements the ClientAPIModule interface for admin-related actions (reports, emojis, etc) type Module struct { config *config.Config - processor message.Processor + processor processing.Processor log *logrus.Logger } // New returns a new admin module -func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { return &Module{ config: config, processor: processor, diff --git a/internal/api/client/app/app.go b/internal/api/client/app/app.go index d1e732a8c..0366ae21f 100644 --- a/internal/api/client/app/app.go +++ b/internal/api/client/app/app.go @@ -24,7 +24,7 @@ import ( "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" - "github.com/superseriousbusiness/gotosocial/internal/message" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/router" ) @@ -34,12 +34,12 @@ const BasePath = "/api/v1/apps" // Module implements the ClientAPIModule interface for requests relating to registering/removing applications type Module struct { config *config.Config - processor message.Processor + processor processing.Processor log *logrus.Logger } // New returns a new auth module -func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { return &Module{ config: config, processor: processor, diff --git a/internal/api/client/fileserver/fileserver.go b/internal/api/client/fileserver/fileserver.go index 63d323a01..b06f48067 100644 --- a/internal/api/client/fileserver/fileserver.go +++ b/internal/api/client/fileserver/fileserver.go @@ -27,7 +27,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" - "github.com/superseriousbusiness/gotosocial/internal/message" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/router" ) @@ -46,13 +46,13 @@ const ( // The goal here is to serve requested media files if the gotosocial server is configured to use local storage. type FileServer struct { config *config.Config - processor message.Processor + processor processing.Processor log *logrus.Logger storageBase string } // New returns a new fileServer module -func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { return &FileServer{ config: config, processor: processor, diff --git a/internal/api/client/fileserver/servefile_test.go b/internal/api/client/fileserver/servefile_test.go index 09fd8ea43..2646da24d 100644 --- a/internal/api/client/fileserver/servefile_test.go +++ b/internal/api/client/fileserver/servefile_test.go @@ -31,14 +31,14 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/api/client/fileserver" + "github.com/superseriousbusiness/gotosocial/internal/blob" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/federation" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/media" - "github.com/superseriousbusiness/gotosocial/internal/message" "github.com/superseriousbusiness/gotosocial/internal/oauth" - "github.com/superseriousbusiness/gotosocial/internal/storage" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/typeutils" "github.com/superseriousbusiness/gotosocial/testrig" ) @@ -49,10 +49,10 @@ type ServeFileTestSuite struct { config *config.Config db db.DB log *logrus.Logger - storage storage.Storage + storage blob.Storage federator federation.Federator tc typeutils.TypeConverter - processor message.Processor + processor processing.Processor mediaHandler media.Handler oauthServer oauth.Server diff --git a/internal/api/client/followrequest/followrequest.go b/internal/api/client/followrequest/followrequest.go index 8be957009..71352294c 100644 --- a/internal/api/client/followrequest/followrequest.go +++ b/internal/api/client/followrequest/followrequest.go @@ -24,7 +24,7 @@ import ( "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" - "github.com/superseriousbusiness/gotosocial/internal/message" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/router" ) @@ -46,12 +46,12 @@ const ( // Module implements the ClientAPIModule interface for every related to interacting with follow requests type Module struct { config *config.Config - processor message.Processor + processor processing.Processor log *logrus.Logger } // New returns a new follow request module -func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { return &Module{ config: config, processor: processor, diff --git a/internal/api/client/instance/instance.go b/internal/api/client/instance/instance.go index ba54480a5..7fb08f29c 100644 --- a/internal/api/client/instance/instance.go +++ b/internal/api/client/instance/instance.go @@ -6,7 +6,7 @@ import ( "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" - "github.com/superseriousbusiness/gotosocial/internal/message" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/router" ) @@ -18,12 +18,12 @@ const ( // Module implements the ClientModule interface type Module struct { config *config.Config - processor message.Processor + processor processing.Processor log *logrus.Logger } // New returns a new instance information module -func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { return &Module{ config: config, processor: processor, diff --git a/internal/api/client/media/media.go b/internal/api/client/media/media.go index f68a73c2c..05058e2e2 100644 --- a/internal/api/client/media/media.go +++ b/internal/api/client/media/media.go @@ -27,7 +27,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" - "github.com/superseriousbusiness/gotosocial/internal/message" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/router" ) @@ -43,12 +43,12 @@ const BasePathWithID = BasePath + "/:" + IDKey // Module implements the ClientAPIModule interface for media type Module struct { config *config.Config - processor message.Processor + processor processing.Processor log *logrus.Logger } // New returns a new auth module -func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { return &Module{ config: config, processor: processor, diff --git a/internal/api/client/media/mediacreate_test.go b/internal/api/client/media/mediacreate_test.go index e86c66021..bed588017 100644 --- a/internal/api/client/media/mediacreate_test.go +++ b/internal/api/client/media/mediacreate_test.go @@ -34,14 +34,14 @@ import ( "github.com/stretchr/testify/suite" mediamodule "github.com/superseriousbusiness/gotosocial/internal/api/client/media" "github.com/superseriousbusiness/gotosocial/internal/api/model" + "github.com/superseriousbusiness/gotosocial/internal/blob" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/federation" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/media" - "github.com/superseriousbusiness/gotosocial/internal/message" "github.com/superseriousbusiness/gotosocial/internal/oauth" - "github.com/superseriousbusiness/gotosocial/internal/storage" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/typeutils" "github.com/superseriousbusiness/gotosocial/testrig" ) @@ -52,12 +52,12 @@ type MediaCreateTestSuite struct { config *config.Config db db.DB log *logrus.Logger - storage storage.Storage + storage blob.Storage federator federation.Federator tc typeutils.TypeConverter mediaHandler media.Handler oauthServer oauth.Server - processor message.Processor + processor processing.Processor // standard suite models testTokens map[string]*oauth.Token diff --git a/internal/api/client/notification/notification.go b/internal/api/client/notification/notification.go index bc06b31e4..799d0a5e3 100644 --- a/internal/api/client/notification/notification.go +++ b/internal/api/client/notification/notification.go @@ -24,7 +24,7 @@ import ( "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" - "github.com/superseriousbusiness/gotosocial/internal/message" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/router" ) @@ -39,19 +39,19 @@ const ( // MaxIDKey is the url query for setting a max notification ID to return MaxIDKey = "max_id" - // Limit key is for specifying maximum number of notifications to return. + // LimitKey is for specifying maximum number of notifications to return. LimitKey = "limit" ) // Module implements the ClientAPIModule interface for every related to posting/deleting/interacting with notifications type Module struct { config *config.Config - processor message.Processor + processor processing.Processor log *logrus.Logger } // New returns a new notification module -func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { return &Module{ config: config, processor: processor, diff --git a/internal/api/client/notification/notificationsget.go b/internal/api/client/notification/notificationsget.go index 3e4970800..a2d049384 100644 --- a/internal/api/client/notification/notificationsget.go +++ b/internal/api/client/notification/notificationsget.go @@ -27,6 +27,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/oauth" ) +// NotificationsGETHandler serves a list of notifications to the caller, with the desired query parameters func (m *Module) NotificationsGETHandler(c *gin.Context) { l := m.log.WithFields(logrus.Fields{ "func": "NotificationsGETHandler", diff --git a/internal/api/client/search/search.go b/internal/api/client/search/search.go index b89ae1a74..1cffee5e0 100644 --- a/internal/api/client/search/search.go +++ b/internal/api/client/search/search.go @@ -24,12 +24,12 @@ import ( "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" - "github.com/superseriousbusiness/gotosocial/internal/message" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/router" ) const ( - // BasePath is the base path for serving v1 of the search API + // BasePathV1 is the base path for serving v1 of the search API BasePathV1 = "/api/v1/search" // BasePathV2 is the base path for serving v2 of the search API @@ -67,12 +67,12 @@ const ( // Module implements the ClientAPIModule interface for everything related to searching type Module struct { config *config.Config - processor message.Processor + processor processing.Processor log *logrus.Logger } // New returns a new search module -func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { return &Module{ config: config, processor: processor, diff --git a/internal/api/client/status/status.go b/internal/api/client/status/status.go index a91f1fa67..e71764eb1 100644 --- a/internal/api/client/status/status.go +++ b/internal/api/client/status/status.go @@ -26,7 +26,7 @@ import ( "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" - "github.com/superseriousbusiness/gotosocial/internal/message" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/router" ) @@ -75,12 +75,12 @@ const ( // Module implements the ClientAPIModule interface for every related to posting/deleting/interacting with statuses type Module struct { config *config.Config - processor message.Processor + processor processing.Processor log *logrus.Logger } // New returns a new account module -func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { return &Module{ config: config, processor: processor, diff --git a/internal/api/client/status/status_test.go b/internal/api/client/status/status_test.go index 0f77820a1..563a23ce2 100644 --- a/internal/api/client/status/status_test.go +++ b/internal/api/client/status/status_test.go @@ -22,13 +22,13 @@ import ( "github.com/sirupsen/logrus" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/api/client/status" + "github.com/superseriousbusiness/gotosocial/internal/blob" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/federation" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" - "github.com/superseriousbusiness/gotosocial/internal/message" "github.com/superseriousbusiness/gotosocial/internal/oauth" - "github.com/superseriousbusiness/gotosocial/internal/storage" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/typeutils" ) @@ -41,8 +41,8 @@ type StatusStandardTestSuite struct { log *logrus.Logger tc typeutils.TypeConverter federator federation.Federator - processor message.Processor - storage storage.Storage + processor processing.Processor + storage blob.Storage // standard suite models testTokens map[string]*oauth.Token diff --git a/internal/api/client/timeline/timeline.go b/internal/api/client/timeline/timeline.go index 84674132c..f563d6b7d 100644 --- a/internal/api/client/timeline/timeline.go +++ b/internal/api/client/timeline/timeline.go @@ -24,7 +24,7 @@ import ( "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" - "github.com/superseriousbusiness/gotosocial/internal/message" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/router" ) @@ -39,7 +39,7 @@ const ( SinceIDKey = "since_id" // MinIDKey is the url query for returning results immediately newer than the given ID MinIDKey = "min_id" - // Limit key is for specifying maximum number of results to return. + // LimitKey is for specifying maximum number of results to return. LimitKey = "limit" // LocalKey is for specifying whether only local statuses should be returned LocalKey = "local" @@ -48,12 +48,12 @@ const ( // Module implements the ClientAPIModule interface for everything relating to viewing timelines type Module struct { config *config.Config - processor message.Processor + processor processing.Processor log *logrus.Logger } // New returns a new timeline module -func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { return &Module{ config: config, processor: processor, diff --git a/internal/api/s2s/user/followers.go b/internal/api/s2s/user/followers.go index 0b633619f..9ccf9c4d5 100644 --- a/internal/api/s2s/user/followers.go +++ b/internal/api/s2s/user/followers.go @@ -25,6 +25,7 @@ import ( "github.com/sirupsen/logrus" ) +// FollowersGETHandler returns a collection of URIs for followers of the target user, formatted so that other AP servers can understand it. func (m *Module) FollowersGETHandler(c *gin.Context) { l := m.log.WithFields(logrus.Fields{ "func": "FollowersGETHandler", diff --git a/internal/api/s2s/user/following.go b/internal/api/s2s/user/following.go index de5701f8d..f19965c26 100644 --- a/internal/api/s2s/user/following.go +++ b/internal/api/s2s/user/following.go @@ -25,6 +25,7 @@ import ( "github.com/sirupsen/logrus" ) +// FollowingGETHandler returns a collection of URIs for accounts that the target user follows, formatted so that other AP servers can understand it. func (m *Module) FollowingGETHandler(c *gin.Context) { l := m.log.WithFields(logrus.Fields{ "func": "FollowingGETHandler", diff --git a/internal/api/s2s/user/inboxpost.go b/internal/api/s2s/user/inboxpost.go index 60b74ab70..642ba6498 100644 --- a/internal/api/s2s/user/inboxpost.go +++ b/internal/api/s2s/user/inboxpost.go @@ -23,7 +23,7 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" - "github.com/superseriousbusiness/gotosocial/internal/message" + "github.com/superseriousbusiness/gotosocial/internal/processing" ) // InboxPOSTHandler deals with incoming POST requests to an actor's inbox. @@ -42,7 +42,7 @@ func (m *Module) InboxPOSTHandler(c *gin.Context) { posted, err := m.processor.InboxPost(c.Request.Context(), c.Writer, c.Request) if err != nil { - if withCode, ok := err.(message.ErrorWithCode); ok { + if withCode, ok := err.(processing.ErrorWithCode); ok { l.Debug(withCode.Error()) c.JSON(withCode.Code(), withCode.Safe()) return diff --git a/internal/api/s2s/user/statusget.go b/internal/api/s2s/user/statusget.go index 60efd484e..22774ae2c 100644 --- a/internal/api/s2s/user/statusget.go +++ b/internal/api/s2s/user/statusget.go @@ -7,6 +7,7 @@ import ( "github.com/sirupsen/logrus" ) +// StatusGETHandler serves the target status as an activitystreams NOTE so that other AP servers can parse it. func (m *Module) StatusGETHandler(c *gin.Context) { l := m.log.WithFields(logrus.Fields{ "func": "StatusGETHandler", diff --git a/internal/api/s2s/user/user.go b/internal/api/s2s/user/user.go index e1bdb9a8d..ffb308038 100644 --- a/internal/api/s2s/user/user.go +++ b/internal/api/s2s/user/user.go @@ -24,7 +24,7 @@ import ( "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" - "github.com/superseriousbusiness/gotosocial/internal/message" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/router" "github.com/superseriousbusiness/gotosocial/internal/util" ) @@ -60,12 +60,12 @@ var ActivityPubAcceptHeaders = []string{ // Module implements the FederationAPIModule interface type Module struct { config *config.Config - processor message.Processor + processor processing.Processor log *logrus.Logger } // New returns a new auth module -func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.FederationModule { +func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.FederationModule { return &Module{ config: config, processor: processor, diff --git a/internal/api/s2s/user/user_test.go b/internal/api/s2s/user/user_test.go index 84e35ab68..91d1ea32d 100644 --- a/internal/api/s2s/user/user_test.go +++ b/internal/api/s2s/user/user_test.go @@ -4,13 +4,13 @@ import ( "github.com/sirupsen/logrus" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/api/s2s/user" + "github.com/superseriousbusiness/gotosocial/internal/blob" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/federation" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" - "github.com/superseriousbusiness/gotosocial/internal/message" "github.com/superseriousbusiness/gotosocial/internal/oauth" - "github.com/superseriousbusiness/gotosocial/internal/storage" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/typeutils" ) @@ -23,8 +23,8 @@ type UserStandardTestSuite struct { log *logrus.Logger tc typeutils.TypeConverter federator federation.Federator - processor message.Processor - storage storage.Storage + processor processing.Processor + storage blob.Storage // standard suite models testTokens map[string]*oauth.Token diff --git a/internal/api/s2s/webfinger/webfinger.go b/internal/api/s2s/webfinger/webfinger.go index 168fe1e76..6d48dc80a 100644 --- a/internal/api/s2s/webfinger/webfinger.go +++ b/internal/api/s2s/webfinger/webfinger.go @@ -24,7 +24,7 @@ import ( "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" - "github.com/superseriousbusiness/gotosocial/internal/message" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/router" ) @@ -36,12 +36,12 @@ const ( // Module implements the FederationModule interface type Module struct { config *config.Config - processor message.Processor + processor processing.Processor log *logrus.Logger } // New returns a new webfinger module -func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.FederationModule { +func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.FederationModule { return &Module{ config: config, processor: processor, diff --git a/internal/storage/inmem.go b/internal/blob/inmem.go index a596c3d97..6ea64bcfe 100644 --- a/internal/storage/inmem.go +++ b/internal/blob/inmem.go @@ -1,4 +1,4 @@ -package storage +package blob import ( "fmt" diff --git a/internal/storage/local.go b/internal/blob/local.go index 3b64524f6..01f82f8d2 100644 --- a/internal/storage/local.go +++ b/internal/blob/local.go @@ -1,4 +1,4 @@ -package storage +package blob import ( "fmt" diff --git a/internal/storage/storage.go b/internal/blob/storage.go index 409c90b37..d1deb740f 100644 --- a/internal/storage/storage.go +++ b/internal/blob/storage.go @@ -16,8 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -// Package storage contains an interface and implementations for storing and retrieving files and attachments. -package storage +package blob // Storage is an interface for storing and retrieving blobs // such as images, videos, and any other attachments/documents diff --git a/internal/action/action.go b/internal/cliactions/action.go index de803ba7c..3ba91de8d 100644 --- a/internal/action/action.go +++ b/internal/cliactions/action.go @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package action +package cliactions import ( "context" diff --git a/internal/clitools/admin/account/account.go b/internal/cliactions/admin/account/account.go index da4de4711..3bb1afada 100644 --- a/internal/clitools/admin/account/account.go +++ b/internal/cliactions/admin/account/account.go @@ -25,7 +25,7 @@ import ( "time" "github.com/sirupsen/logrus" - "github.com/superseriousbusiness/gotosocial/internal/action" + "github.com/superseriousbusiness/gotosocial/internal/cliactions" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db/pg" @@ -34,7 +34,7 @@ import ( ) // Create creates a new account in the database using the provided flags. -var Create action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { +var Create cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { dbConn, err := pg.NewPostgresService(ctx, c, log) if err != nil { return fmt.Errorf("error creating dbservice: %s", err) @@ -73,7 +73,7 @@ var Create action.GTSAction = func(ctx context.Context, c *config.Config, log *l } // Confirm sets a user to Approved, sets Email to the current UnconfirmedEmail value, and sets ConfirmedAt to now. -var Confirm action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { +var Confirm cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { dbConn, err := pg.NewPostgresService(ctx, c, log) if err != nil { return fmt.Errorf("error creating dbservice: %s", err) @@ -108,7 +108,7 @@ var Confirm action.GTSAction = func(ctx context.Context, c *config.Config, log * } // Promote sets a user to admin. -var Promote action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { +var Promote cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { dbConn, err := pg.NewPostgresService(ctx, c, log) if err != nil { return fmt.Errorf("error creating dbservice: %s", err) @@ -140,7 +140,7 @@ var Promote action.GTSAction = func(ctx context.Context, c *config.Config, log * } // Demote sets admin on a user to false. -var Demote action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { +var Demote cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { dbConn, err := pg.NewPostgresService(ctx, c, log) if err != nil { return fmt.Errorf("error creating dbservice: %s", err) @@ -172,7 +172,7 @@ var Demote action.GTSAction = func(ctx context.Context, c *config.Config, log *l } // Disable sets Disabled to true on a user. -var Disable action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { +var Disable cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { dbConn, err := pg.NewPostgresService(ctx, c, log) if err != nil { return fmt.Errorf("error creating dbservice: %s", err) @@ -203,7 +203,8 @@ var Disable action.GTSAction = func(ctx context.Context, c *config.Config, log * return dbConn.Stop(ctx) } -var Suspend action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { +// Suspend suspends the target account, cleanly removing all of its media, followers, following, likes, statuses, etc. +var Suspend cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { // TODO return nil } diff --git a/internal/gotosocial/actions.go b/internal/cliactions/server/server.go index b8f888a76..75337009a 100644 --- a/internal/gotosocial/actions.go +++ b/internal/cliactions/server/server.go @@ -1,22 +1,4 @@ -/* - GoToSocial - Copyright (C) 2021 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 gotosocial +package server import ( "context" @@ -27,7 +9,6 @@ import ( "syscall" "github.com/sirupsen/logrus" - "github.com/superseriousbusiness/gotosocial/internal/action" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/api/client/account" "github.com/superseriousbusiness/gotosocial/internal/api/client/admin" @@ -44,16 +25,18 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/api/s2s/user" "github.com/superseriousbusiness/gotosocial/internal/api/s2s/webfinger" "github.com/superseriousbusiness/gotosocial/internal/api/security" + "github.com/superseriousbusiness/gotosocial/internal/blob" + "github.com/superseriousbusiness/gotosocial/internal/cliactions" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db/pg" "github.com/superseriousbusiness/gotosocial/internal/federation" "github.com/superseriousbusiness/gotosocial/internal/federation/federatingdb" + "github.com/superseriousbusiness/gotosocial/internal/gotosocial" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/media" - "github.com/superseriousbusiness/gotosocial/internal/message" "github.com/superseriousbusiness/gotosocial/internal/oauth" + "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/router" - "github.com/superseriousbusiness/gotosocial/internal/storage" "github.com/superseriousbusiness/gotosocial/internal/transport" "github.com/superseriousbusiness/gotosocial/internal/typeutils" ) @@ -81,8 +64,8 @@ var models []interface{} = []interface{}{ &oauth.Client{}, } -// Run creates and starts a gotosocial server -var Run action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { +// Start creates and starts a gotosocial server +var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { dbService, err := pg.NewPostgresService(ctx, c, log) if err != nil { return fmt.Errorf("error creating dbservice: %s", err) @@ -95,7 +78,7 @@ var Run action.GTSAction = func(ctx context.Context, c *config.Config, log *logr return fmt.Errorf("error creating router: %s", err) } - storageBackend, err := storage.NewLocal(c, log) + storageBackend, err := blob.NewLocal(c, log) if err != nil { return fmt.Errorf("error creating storage backend: %s", err) } @@ -108,7 +91,7 @@ var Run action.GTSAction = func(ctx context.Context, c *config.Config, log *logr oauthServer := oauth.New(dbService, log) transportController := transport.NewController(c, &federation.Clock{}, http.DefaultClient, log) federator := federation.NewFederator(dbService, federatingDB, transportController, c, log, typeConverter) - processor := message.NewProcessor(c, typeConverter, federator, oauthServer, mediaHandler, storageBackend, dbService, log) + processor := processing.NewProcessor(c, typeConverter, federator, oauthServer, mediaHandler, storageBackend, dbService, log) if err := processor.Start(); err != nil { return fmt.Errorf("error starting processor: %s", err) } @@ -171,7 +154,7 @@ var Run action.GTSAction = func(ctx context.Context, c *config.Config, log *logr return fmt.Errorf("error creating instance instance: %s", err) } - gts, err := New(dbService, router, federator, c) + gts, err := gotosocial.NewServer(dbService, router, federator, c) if err != nil { return fmt.Errorf("error creating gotosocial service: %s", err) } diff --git a/internal/config/config.go b/internal/config/config.go index c06f45384..8a5e27a0c 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -26,6 +26,7 @@ import ( "gopkg.in/yaml.v2" ) +// Flags and usage strings for configuration. const ( UsernameFlag = "username" UsernameUsage = "the username to create/delete/etc" diff --git a/internal/db/db.go b/internal/db/db.go index ea6f808cf..31a8ba5d9 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -30,34 +30,10 @@ const ( DBTypePostgres string = "POSTGRES" ) -// ErrNoEntries is to be returned from the DB interface when no entries are found for a given query. -type ErrNoEntries struct{} - -func (e ErrNoEntries) Error() string { - return "no entries" -} - -// ErrAlreadyExists is to be returned from the DB interface when an entry already exists for a given query or its constraints. -type ErrAlreadyExists struct{} - -func (e ErrAlreadyExists) Error() string { - return "already exists" -} - -type Where struct { - Key string - Value interface{} - CaseInsensitive bool -} - // DB provides methods for interacting with an underlying database or other storage mechanism (for now, just postgres). // Note that in all of the functions below, the passed interface should be a pointer or a slice, which will then be populated // by whatever is returned from the database. type DB interface { - // Federation returns an interface that's compatible with go-fed, for performing federation storage/retrieval functions. - // See: https://pkg.go.dev/github.com/go-fed/activity@v1.0.0/pub?utm_source=gopls#Database - // Federation() federatingdb.FederatingDB - /* BASIC DB FUNCTIONALITY */ @@ -269,10 +245,6 @@ type DB interface { // StatusBookmarkedBy checks if a given status has been bookmarked by a given account ID StatusBookmarkedBy(status *gtsmodel.Status, accountID string) (bool, error) - // FaveStatus faves the given status, using accountID as the faver. - // The returned fave will be nil if the status was already faved. - // FaveStatus(status *gtsmodel.Status, accountID string) (*gtsmodel.StatusFave, error) - // UnfaveStatus unfaves the given status, using accountID as the unfaver (sure, that's a word). // The returned fave will be nil if the status was already not faved. UnfaveStatus(status *gtsmodel.Status, accountID string) (*gtsmodel.StatusFave, error) @@ -285,6 +257,7 @@ type DB interface { // It will use the given filters and try to return as many statuses up to the limit as possible. GetHomeTimelineForAccount(accountID string, maxID string, sinceID string, minID string, limit int, local bool) ([]*gtsmodel.Status, error) + // GetNotificationsForAccount returns a list of notifications that pertain to the given accountID. GetNotificationsForAccount(accountID string, limit int, maxID string) ([]*gtsmodel.Notification, error) /* diff --git a/internal/db/actions.go b/internal/db/error.go index 4288f5fdb..197c7bd68 100644 --- a/internal/db/actions.go +++ b/internal/db/error.go @@ -18,20 +18,16 @@ package db -import ( - "context" - - "github.com/sirupsen/logrus" - "github.com/superseriousbusiness/gotosocial/internal/action" - "github.com/superseriousbusiness/gotosocial/internal/config" -) - -// Initialize will initialize the database given in the config for use with GoToSocial -var Initialize action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { - // db, err := New(ctx, c, log) - // if err != nil { - // return err - // } - return nil - // return db.CreateSchema(ctx) +// ErrNoEntries is to be returned from the DB interface when no entries are found for a given query. +type ErrNoEntries struct{} + +func (e ErrNoEntries) Error() string { + return "no entries" +} + +// ErrAlreadyExists is to be returned from the DB interface when an entry already exists for a given query or its constraints. +type ErrAlreadyExists struct{} + +func (e ErrAlreadyExists) Error() string { + return "already exists" } diff --git a/internal/db/params.go b/internal/db/params.go new file mode 100644 index 000000000..f0c384435 --- /dev/null +++ b/internal/db/params.go @@ -0,0 +1,30 @@ +/* + GoToSocial + Copyright (C) 2021 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 db + +// Where allows the caller of the DB to specify Where parameters. +type Where struct { + // The table to search on. + Key string + // The value that must be set. + Value interface{} + // Whether the value (if a string) should be case sensitive or not. + // Defaults to false. + CaseInsensitive bool +} diff --git a/internal/federation/federator_test.go b/internal/federation/federator_test.go index e5d42b53d..9783fd3a6 100644 --- a/internal/federation/federator_test.go +++ b/internal/federation/federator_test.go @@ -35,11 +35,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" + "github.com/superseriousbusiness/gotosocial/internal/blob" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/federation" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" - "github.com/superseriousbusiness/gotosocial/internal/storage" "github.com/superseriousbusiness/gotosocial/internal/typeutils" "github.com/superseriousbusiness/gotosocial/internal/util" "github.com/superseriousbusiness/gotosocial/testrig" @@ -50,7 +50,7 @@ type ProtocolTestSuite struct { config *config.Config db db.DB log *logrus.Logger - storage storage.Storage + storage blob.Storage typeConverter typeutils.TypeConverter accounts map[string]*gtsmodel.Account activities map[string]testrig.ActivityWithSignature diff --git a/internal/gotosocial/gotosocial.go b/internal/gotosocial/gotosocial.go index f20e1161d..e998c16f9 100644 --- a/internal/gotosocial/gotosocial.go +++ b/internal/gotosocial/gotosocial.go @@ -27,17 +27,22 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/router" ) -// Gotosocial is the 'main' function of the gotosocial server, and the place where everything hangs together. +// Server is the 'main' function of the gotosocial server, and the place where everything hangs together. // The logic of stopping and starting the entire server is contained here. -type Gotosocial interface { +type Server interface { + // Start starts up the gotosocial server. If something goes wrong + // while starting the server, then an error will be returned. Start(context.Context) error + // Stop closes down the gotosocial server, first closing the router + // then the database. If something goes wrong while stopping, an + // error will be returned. Stop(context.Context) error } -// New returns a new gotosocial server, initialized with the given configuration. +// NewServer returns a new gotosocial server, initialized with the given configuration. // An error will be returned the caller if something goes wrong during initialization // eg., no db or storage connection, port for router already in use, etc. -func New(db db.DB, apiRouter router.Router, federator federation.Federator, config *config.Config) (Gotosocial, error) { +func NewServer(db db.DB, apiRouter router.Router, federator federation.Federator, config *config.Config) (Server, error) { return &gotosocial{ db: db, apiRouter: apiRouter, @@ -61,6 +66,9 @@ func (gts *gotosocial) Start(ctx context.Context) error { return nil } +// Stop closes down the gotosocial server, first closing the router +// then the database. If something goes wrong while stopping, an +// error will be returned. func (gts *gotosocial) Stop(ctx context.Context) error { if err := gts.apiRouter.Stop(ctx); err != nil { return err diff --git a/internal/gtsmodel/notification.go b/internal/gtsmodel/notification.go index 35e0ca173..5084d46c0 100644 --- a/internal/gtsmodel/notification.go +++ b/internal/gtsmodel/notification.go @@ -61,7 +61,7 @@ const ( NotificationMention NotificationType = "mention" // NotificationReblog -- someone boosted one of your statuses NotificationReblog NotificationType = "reblog" - // NotifiationFave -- someone faved/liked one of your statuses + // NotificationFave -- someone faved/liked one of your statuses NotificationFave NotificationType = "favourite" // NotificationPoll -- a poll you voted in or created has ended NotificationPoll NotificationType = "poll" diff --git a/internal/media/handler.go b/internal/media/handler.go index b59e836ed..acfc823ed 100644 --- a/internal/media/handler.go +++ b/internal/media/handler.go @@ -28,10 +28,10 @@ import ( "github.com/google/uuid" "github.com/sirupsen/logrus" + "github.com/superseriousbusiness/gotosocial/internal/blob" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" - "github.com/superseriousbusiness/gotosocial/internal/storage" "github.com/superseriousbusiness/gotosocial/internal/transport" ) @@ -93,12 +93,12 @@ type Handler interface { type mediaHandler struct { config *config.Config db db.DB - storage storage.Storage + storage blob.Storage log *logrus.Logger } // New returns a new handler with the given config, db, storage, and logger -func New(config *config.Config, database db.DB, storage storage.Storage, log *logrus.Logger) Handler { +func New(config *config.Config, database db.DB, storage blob.Storage, log *logrus.Logger) Handler { return &mediaHandler{ config: config, db: database, diff --git a/internal/media/handler_test.go b/internal/media/handler_test.go deleted file mode 100644 index 02bf334c5..000000000 --- a/internal/media/handler_test.go +++ /dev/null @@ -1,173 +0,0 @@ -/* - GoToSocial - Copyright (C) 2021 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 media - -import ( - "context" - "io/ioutil" - "testing" - - "github.com/sirupsen/logrus" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/suite" - "github.com/superseriousbusiness/gotosocial/internal/config" - "github.com/superseriousbusiness/gotosocial/internal/db" - "github.com/superseriousbusiness/gotosocial/internal/db/pg" - "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" - "github.com/superseriousbusiness/gotosocial/internal/storage" -) - -type MediaTestSuite struct { - suite.Suite - config *config.Config - log *logrus.Logger - db db.DB - mediaHandler *mediaHandler - mockStorage *storage.MockStorage -} - -/* - TEST INFRASTRUCTURE -*/ - -// SetupSuite sets some variables on the suite that we can use as consts (more or less) throughout -func (suite *MediaTestSuite) SetupSuite() { - // some of our subsequent entities need a log so create this here - log := logrus.New() - log.SetLevel(logrus.TraceLevel) - suite.log = log - - // Direct config to local postgres instance - c := config.Empty() - c.Protocol = "http" - c.Host = "localhost" - c.DBConfig = &config.DBConfig{ - Type: "postgres", - Address: "localhost", - Port: 5432, - User: "postgres", - Password: "postgres", - Database: "postgres", - ApplicationName: "gotosocial", - } - c.MediaConfig = &config.MediaConfig{ - MaxImageSize: 2 << 20, - } - c.StorageConfig = &config.StorageConfig{ - Backend: "local", - BasePath: "/tmp", - ServeProtocol: "http", - ServeHost: "localhost", - ServeBasePath: "/fileserver/media", - } - suite.config = c - // use an actual database for this, because it's just easier than mocking one out - database, err := pg.NewPostgresService(context.Background(), c, log) - if err != nil { - suite.FailNow(err.Error()) - } - suite.db = database - - suite.mockStorage = &storage.MockStorage{} - // We don't need storage to do anything for these tests, so just simulate a success and do nothing - suite.mockStorage.On("StoreFileAt", mock.AnythingOfType("string"), mock.AnythingOfType("[]uint8")).Return(nil) - - // and finally here's the thing we're actually testing! - suite.mediaHandler = &mediaHandler{ - config: suite.config, - db: suite.db, - storage: suite.mockStorage, - log: log, - } -} - -func (suite *MediaTestSuite) TearDownSuite() { - if err := suite.db.Stop(context.Background()); err != nil { - logrus.Panicf("error closing db connection: %s", err) - } -} - -// SetupTest creates a db connection and creates necessary tables before each test -func (suite *MediaTestSuite) SetupTest() { - // create all the tables we might need in thie suite - models := []interface{}{ - >smodel.Account{}, - >smodel.MediaAttachment{}, - } - for _, m := range models { - if err := suite.db.CreateTable(m); err != nil { - logrus.Panicf("db connection error: %s", err) - } - } - - err := suite.db.CreateInstanceAccount() - if err != nil { - logrus.Panic(err) - } -} - -// TearDownTest drops tables to make sure there's no data in the db -func (suite *MediaTestSuite) TearDownTest() { - - // remove all the tables we might have used so it's clear for the next test - models := []interface{}{ - >smodel.Account{}, - >smodel.MediaAttachment{}, - } - for _, m := range models { - if err := suite.db.DropTable(m); err != nil { - logrus.Panicf("error dropping table: %s", err) - } - } -} - -/* - ACTUAL TESTS -*/ - -func (suite *MediaTestSuite) TestSetHeaderOrAvatarForAccountID() { - // load test image - f, err := ioutil.ReadFile("./test/test-jpeg.jpg") - assert.Nil(suite.T(), err) - - ma, err := suite.mediaHandler.ProcessHeaderOrAvatar(f, "weeeeeee", "header", "") - assert.Nil(suite.T(), err) - suite.log.Debugf("%+v", ma) - - // attachment should have.... - assert.Equal(suite.T(), "weeeeeee", ma.AccountID) - assert.Equal(suite.T(), "LjCZnlvyRkRn_NvzRjWF?urqV@f9", ma.Blurhash) - //TODO: add more checks here, cba right now! -} - -func (suite *MediaTestSuite) TestProcessLocalEmoji() { - f, err := ioutil.ReadFile("./test/rainbow-original.png") - assert.NoError(suite.T(), err) - - emoji, err := suite.mediaHandler.ProcessLocalEmoji(f, "rainbow") - assert.NoError(suite.T(), err) - suite.log.Debugf("%+v", emoji) -} - -// TODO: add tests for sad path, gif, png.... - -func TestMediaTestSuite(t *testing.T) { - suite.Run(t, new(MediaTestSuite)) -} diff --git a/internal/message/notificationsprocess.go b/internal/message/notificationsprocess.go deleted file mode 100644 index 64726b75f..000000000 --- a/internal/message/notificationsprocess.go +++ /dev/null @@ -1,24 +0,0 @@ -package message - -import ( - apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" - "github.com/superseriousbusiness/gotosocial/internal/oauth" -) - -func (p *processor) NotificationsGet(authed *oauth.Auth, limit int, maxID string) ([]*apimodel.Notification, ErrorWithCode) { - notifs, err := p.db.GetNotificationsForAccount(authed.Account.ID, limit, maxID) - if err != nil { - return nil, NewErrorInternalError(err) - } - - mastoNotifs := []*apimodel.Notification{} - for _, n := range notifs { - mastoNotif, err := p.tc.NotificationToMasto(n) - if err != nil { - return nil, NewErrorInternalError(err) - } - mastoNotifs = append(mastoNotifs, mastoNotif) - } - - return mastoNotifs, nil -} diff --git a/internal/oauth/mock_Server.go b/internal/oauth/mock_Server.go deleted file mode 100644 index a5c0d603e..000000000 --- a/internal/oauth/mock_Server.go +++ /dev/null @@ -1,89 +0,0 @@ -// Code generated by mockery v2.7.4. DO NOT EDIT. - -package oauth - -import ( - http "net/http" - - mock "github.com/stretchr/testify/mock" - oauth2 "github.com/superseriousbusiness/oauth2/v4" -) - -// MockServer is an autogenerated mock type for the Server type -type MockServer struct { - mock.Mock -} - -// GenerateUserAccessToken provides a mock function with given fields: ti, clientSecret, userID -func (_m *MockServer) GenerateUserAccessToken(ti oauth2.TokenInfo, clientSecret string, userID string) (oauth2.TokenInfo, error) { - ret := _m.Called(ti, clientSecret, userID) - - var r0 oauth2.TokenInfo - if rf, ok := ret.Get(0).(func(oauth2.TokenInfo, string, string) oauth2.TokenInfo); ok { - r0 = rf(ti, clientSecret, userID) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(oauth2.TokenInfo) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func(oauth2.TokenInfo, string, string) error); ok { - r1 = rf(ti, clientSecret, userID) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// HandleAuthorizeRequest provides a mock function with given fields: w, r -func (_m *MockServer) HandleAuthorizeRequest(w http.ResponseWriter, r *http.Request) error { - ret := _m.Called(w, r) - - var r0 error - if rf, ok := ret.Get(0).(func(http.ResponseWriter, *http.Request) error); ok { - r0 = rf(w, r) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// HandleTokenRequest provides a mock function with given fields: w, r -func (_m *MockServer) HandleTokenRequest(w http.ResponseWriter, r *http.Request) error { - ret := _m.Called(w, r) - - var r0 error - if rf, ok := ret.Get(0).(func(http.ResponseWriter, *http.Request) error); ok { - r0 = rf(w, r) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// ValidationBearerToken provides a mock function with given fields: r -func (_m *MockServer) ValidationBearerToken(r *http.Request) (oauth2.TokenInfo, error) { - ret := _m.Called(r) - - var r0 oauth2.TokenInfo - if rf, ok := ret.Get(0).(func(*http.Request) oauth2.TokenInfo); ok { - r0 = rf(r) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(oauth2.TokenInfo) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func(*http.Request) error); ok { - r1 = rf(r) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} diff --git a/internal/message/accountprocess.go b/internal/processing/account.go index ea03ab0ff..92ccf10fa 100644 --- a/internal/message/accountprocess.go +++ b/internal/processing/account.go @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package message +package processing import ( "errors" diff --git a/internal/message/adminprocess.go b/internal/processing/admin.go index d26196d79..78979a228 100644 --- a/internal/message/adminprocess.go +++ b/internal/processing/admin.go @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package message +package processing import ( "bytes" diff --git a/internal/message/appprocess.go b/internal/processing/app.go index 2fddb7a90..47fce051b 100644 --- a/internal/message/appprocess.go +++ b/internal/processing/app.go @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package message +package processing import ( "github.com/google/uuid" diff --git a/internal/message/error.go b/internal/processing/error.go index ceeef1b41..1fea01d08 100644 --- a/internal/message/error.go +++ b/internal/processing/error.go @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package message +package processing import ( "errors" diff --git a/internal/message/fediprocess.go b/internal/processing/federation.go index 173da18ee..b93455d6e 100644 --- a/internal/message/fediprocess.go +++ b/internal/processing/federation.go @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package message +package processing import ( "context" diff --git a/internal/message/frprocess.go b/internal/processing/followrequest.go index 41ab285c2..7e606f5da 100644 --- a/internal/message/frprocess.go +++ b/internal/processing/followrequest.go @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package message +package processing import ( apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" diff --git a/internal/message/fromclientapiprocess.go b/internal/processing/fromclientapi.go index 40a2981a8..0d8b73eb0 100644 --- a/internal/message/fromclientapiprocess.go +++ b/internal/processing/fromclientapi.go @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package message +package processing import ( "context" diff --git a/internal/message/fromcommonprocess.go b/internal/processing/fromcommon.go index 19f5829b4..cb38d4bb4 100644 --- a/internal/message/fromcommonprocess.go +++ b/internal/processing/fromcommon.go @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package message +package processing import ( "fmt" diff --git a/internal/message/fromfederatorprocess.go b/internal/processing/fromfederator.go index b070cc46d..479bdec33 100644 --- a/internal/message/fromfederatorprocess.go +++ b/internal/processing/fromfederator.go @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package message +package processing import ( "errors" diff --git a/internal/message/instanceprocess.go b/internal/processing/instance.go index f544fbf30..e928bf642 100644 --- a/internal/message/instanceprocess.go +++ b/internal/processing/instance.go @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package message +package processing import ( "fmt" diff --git a/internal/message/mediaprocess.go b/internal/processing/media.go index 094da7ace..255f49067 100644 --- a/internal/message/mediaprocess.go +++ b/internal/processing/media.go @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package message +package processing import ( "bytes" diff --git a/internal/processing/notification.go b/internal/processing/notification.go new file mode 100644 index 000000000..36cd81b91 --- /dev/null +++ b/internal/processing/notification.go @@ -0,0 +1,45 @@ +/* + GoToSocial + Copyright (C) 2021 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 processing + +import ( + apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" + "github.com/superseriousbusiness/gotosocial/internal/oauth" +) + +func (p *processor) NotificationsGet(authed *oauth.Auth, limit int, maxID string) ([]*apimodel.Notification, ErrorWithCode) { + l := p.log.WithField("func", "NotificationsGet") + + notifs, err := p.db.GetNotificationsForAccount(authed.Account.ID, limit, maxID) + if err != nil { + return nil, NewErrorInternalError(err) + } + + mastoNotifs := []*apimodel.Notification{} + for _, n := range notifs { + mastoNotif, err := p.tc.NotificationToMasto(n) + if err != nil { + l.Debugf("got an error converting a notification to masto, will skip it: %s", err) + continue + } + mastoNotifs = append(mastoNotifs, mastoNotif) + } + + return mastoNotifs, nil +} diff --git a/internal/message/processor.go b/internal/processing/processor.go index e22ed33d6..58b64afab 100644 --- a/internal/message/processor.go +++ b/internal/processing/processor.go @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package message +package processing import ( "context" @@ -24,13 +24,13 @@ import ( "github.com/sirupsen/logrus" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" + "github.com/superseriousbusiness/gotosocial/internal/blob" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/federation" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/oauth" - "github.com/superseriousbusiness/gotosocial/internal/storage" "github.com/superseriousbusiness/gotosocial/internal/typeutils" ) @@ -184,12 +184,12 @@ type processor struct { tc typeutils.TypeConverter oauthServer oauth.Server mediaHandler media.Handler - storage storage.Storage + storage blob.Storage db db.DB } // NewProcessor returns a new Processor that uses the given federator and logger -func NewProcessor(config *config.Config, tc typeutils.TypeConverter, federator federation.Federator, oauthServer oauth.Server, mediaHandler media.Handler, storage storage.Storage, db db.DB, log *logrus.Logger) Processor { +func NewProcessor(config *config.Config, tc typeutils.TypeConverter, federator federation.Federator, oauthServer oauth.Server, mediaHandler media.Handler, storage blob.Storage, db db.DB, log *logrus.Logger) Processor { return &processor{ // toClientAPI: make(chan gtsmodel.ToClientAPI, 100), fromClientAPI: make(chan gtsmodel.FromClientAPI, 100), diff --git a/internal/message/searchprocess.go b/internal/processing/search.go index 873af2507..a712e5e1a 100644 --- a/internal/message/searchprocess.go +++ b/internal/processing/search.go @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package message +package processing import ( "errors" diff --git a/internal/message/statusprocess.go b/internal/processing/status.go index 40c7b30ca..7530f386a 100644 --- a/internal/message/statusprocess.go +++ b/internal/processing/status.go @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package message +package processing import ( "errors" diff --git a/internal/message/timelineprocess.go b/internal/processing/timeline.go index 271d19db5..b7c8e5dc7 100644 --- a/internal/message/timelineprocess.go +++ b/internal/processing/timeline.go @@ -1,14 +1,35 @@ -package message +/* + GoToSocial + Copyright (C) 2021 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 processing import ( "fmt" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" + "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/oauth" ) func (p *processor) HomeTimelineGet(authed *oauth.Auth, maxID string, sinceID string, minID string, limit int, local bool) ([]apimodel.Status, ErrorWithCode) { + l := p.log.WithField("func", "HomeTimelineGet") + statuses, err := p.db.GetHomeTimelineForAccount(authed.Account.ID, maxID, sinceID, minID, limit, local) if err != nil { return nil, NewErrorInternalError(err) @@ -18,12 +39,17 @@ func (p *processor) HomeTimelineGet(authed *oauth.Auth, maxID string, sinceID st for _, s := range statuses { targetAccount := >smodel.Account{} if err := p.db.GetByID(s.AccountID, targetAccount); err != nil { + if _, ok := err.(db.ErrNoEntries); ok { + l.Debugf("skipping status %s because account %s can't be found in the db", s.ID, s.AccountID) + continue + } return nil, NewErrorInternalError(fmt.Errorf("HomeTimelineGet: error getting status author: %s", err)) } relevantAccounts, err := p.db.PullRelevantAccountsFromStatus(s) if err != nil { - return nil, NewErrorInternalError(fmt.Errorf("HomeTimelineGet: error getting relevant statuses for status with id %s and uri %s: %s", s.ID, s.URI, err)) + l.Debugf("skipping status %s because we couldn't pull relevant accounts from the db", s.ID) + continue } visible, err := p.db.StatusVisible(s, targetAccount, authed.Account, relevantAccounts) @@ -38,11 +64,16 @@ func (p *processor) HomeTimelineGet(authed *oauth.Auth, maxID string, sinceID st if s.BoostOfID != "" { bs := >smodel.Status{} if err := p.db.GetByID(s.BoostOfID, bs); err != nil { + if _, ok := err.(db.ErrNoEntries); ok { + l.Debugf("skipping status %s because status %s can't be found in the db", s.ID, s.BoostOfID) + continue + } return nil, NewErrorInternalError(fmt.Errorf("HomeTimelineGet: error getting boosted status: %s", err)) } boostedRelevantAccounts, err := p.db.PullRelevantAccountsFromStatus(bs) if err != nil { - return nil, NewErrorInternalError(fmt.Errorf("HomeTimelineGet: error getting relevant accounts from boosted status: %s", err)) + l.Debugf("skipping status %s because we couldn't pull relevant accounts from the db", s.ID) + continue } boostedVisible, err := p.db.StatusVisible(bs, relevantAccounts.BoostedAccount, authed.Account, boostedRelevantAccounts) @@ -57,7 +88,8 @@ func (p *processor) HomeTimelineGet(authed *oauth.Auth, maxID string, sinceID st apiStatus, err := p.tc.StatusToMasto(s, targetAccount, authed.Account, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostedStatus) if err != nil { - return nil, NewErrorInternalError(fmt.Errorf("HomeTimelineGet: error converting status to masto: %s", err)) + l.Debugf("skipping status %s because it couldn't be converted to its mastodon representation: %s", s.ID, err) + continue } apiStatuses = append(apiStatuses, *apiStatus) diff --git a/internal/message/processorutil.go b/internal/processing/util.go index b053f31a2..af62afbad 100644 --- a/internal/message/processorutil.go +++ b/internal/processing/util.go @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package message +package processing import ( "bytes" diff --git a/internal/router/mock_Router.go b/internal/router/mock_Router.go deleted file mode 100644 index eb8b31115..000000000 --- a/internal/router/mock_Router.go +++ /dev/null @@ -1,44 +0,0 @@ -// Code generated by mockery v2.7.4. DO NOT EDIT. - -package router - -import ( - context "context" - - gin "github.com/gin-gonic/gin" - mock "github.com/stretchr/testify/mock" -) - -// MockRouter is an autogenerated mock type for the Router type -type MockRouter struct { - mock.Mock -} - -// AttachHandler provides a mock function with given fields: method, path, f -func (_m *MockRouter) AttachHandler(method string, path string, f gin.HandlerFunc) { - _m.Called(method, path, f) -} - -// AttachMiddleware provides a mock function with given fields: handler -func (_m *MockRouter) AttachMiddleware(handler gin.HandlerFunc) { - _m.Called(handler) -} - -// Start provides a mock function with given fields: -func (_m *MockRouter) Start() { - _m.Called() -} - -// Stop provides a mock function with given fields: ctx -func (_m *MockRouter) Stop(ctx context.Context) error { - ret := _m.Called(ctx) - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context) error); ok { - r0 = rf(ctx) - } else { - r0 = ret.Error(0) - } - - return r0 -} diff --git a/internal/storage/mock_Storage.go b/internal/storage/mock_Storage.go deleted file mode 100644 index 2444f030a..000000000 --- a/internal/storage/mock_Storage.go +++ /dev/null @@ -1,84 +0,0 @@ -// Code generated by mockery v2.7.4. DO NOT EDIT. - -package storage - -import mock "github.com/stretchr/testify/mock" - -// MockStorage is an autogenerated mock type for the Storage type -type MockStorage struct { - mock.Mock -} - -// ListKeys provides a mock function with given fields: -func (_m *MockStorage) ListKeys() ([]string, error) { - ret := _m.Called() - - var r0 []string - if rf, ok := ret.Get(0).(func() []string); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// RemoveFileAt provides a mock function with given fields: path -func (_m *MockStorage) RemoveFileAt(path string) error { - ret := _m.Called(path) - - var r0 error - if rf, ok := ret.Get(0).(func(string) error); ok { - r0 = rf(path) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// RetrieveFileFrom provides a mock function with given fields: path -func (_m *MockStorage) RetrieveFileFrom(path string) ([]byte, error) { - ret := _m.Called(path) - - var r0 []byte - if rf, ok := ret.Get(0).(func(string) []byte); ok { - r0 = rf(path) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]byte) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// StoreFileAt provides a mock function with given fields: path, data -func (_m *MockStorage) StoreFileAt(path string, data []byte) error { - ret := _m.Called(path, data) - - var r0 error - if rf, ok := ret.Get(0).(func(string, []byte) error); ok { - r0 = rf(path, data) - } else { - r0 = ret.Error(0) - } - - return r0 -} diff --git a/internal/util/uri.go b/internal/util/uri.go index d8dce803b..86a39a75a 100644 --- a/internal/util/uri.go +++ b/internal/util/uri.go @@ -113,7 +113,7 @@ func GenerateURIForFollow(username string, protocol string, host string, thisFol return fmt.Sprintf("%s://%s/%s/%s/%s/%s", protocol, host, UsersPath, username, FollowPath, thisFollowID) } -// GenerateURIForFollow returns the AP URI for a new like/fave -- something like: +// GenerateURIForLike returns the AP URI for a new like/fave -- something like: // https://example.org/users/whatever_user/liked/41c7f33f-1060-48d9-84df-38dcb13cf0d8 func GenerateURIForLike(username string, protocol string, host string, thisFavedID string) string { return fmt.Sprintf("%s://%s/%s/%s/%s/%s", protocol, host, UsersPath, username, LikedPath, thisFavedID) @@ -195,7 +195,7 @@ func IsLikedPath(id *url.URL) bool { return likedPathRegex.MatchString(strings.ToLower(id.Path)) } -// IsLikedPath returns true if the given URL path corresponds to eg /users/example_username/liked/SOME_UUID_OF_A_STATUS +// IsLikePath returns true if the given URL path corresponds to eg /users/example_username/liked/SOME_UUID_OF_A_STATUS func IsLikePath(id *url.URL) bool { return likePathRegex.MatchString(strings.ToLower(id.Path)) } |