From cb8688f4298a1a3ed5e28565004588be3c071df0 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Mon, 20 Dec 2021 15:19:53 +0100 Subject: Remove unnecessary storage config variables (#344) * rewire config to not use extraneous serve vars * rename 'file' to 'local' for consistency * use Type and Size again --- internal/api/client/fileserver/fileserver.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'internal/api/client/fileserver/fileserver.go') diff --git a/internal/api/client/fileserver/fileserver.go b/internal/api/client/fileserver/fileserver.go index 092a15256..c7b08a8e1 100644 --- a/internal/api/client/fileserver/fileserver.go +++ b/internal/api/client/fileserver/fileserver.go @@ -22,14 +22,15 @@ import ( "fmt" "net/http" - "github.com/spf13/viper" "github.com/superseriousbusiness/gotosocial/internal/api" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/router" + "github.com/superseriousbusiness/gotosocial/internal/uris" ) const ( + // FileServeBasePath forms the first part of the fileserver path. + FileServeBasePath = "/" + uris.FileserverPath // AccountIDKey is the url key for account id (an account ulid) AccountIDKey = "account_id" // MediaTypeKey is the url key for media type (usually something like attachment or header etc) @@ -43,20 +44,20 @@ const ( // FileServer implements the RESTAPIModule interface. // The goal here is to serve requested media files if the gotosocial server is configured to use local storage. type FileServer struct { - processor processing.Processor - storageServeBasePath string + processor processing.Processor } // New returns a new fileServer module func New(processor processing.Processor) api.ClientModule { return &FileServer{ - processor: processor, - storageServeBasePath: viper.GetString(config.Keys.StorageServeBasePath), + processor: processor, } } // Route satisfies the RESTAPIModule interface func (m *FileServer) Route(s router.Router) error { - s.AttachHandler(http.MethodGet, fmt.Sprintf("%s/:%s/:%s/:%s/:%s", m.storageServeBasePath, AccountIDKey, MediaTypeKey, MediaSizeKey, FileNameKey), m.ServeFile) + // something like "/fileserver/:account_id/:media_type/:media_size/:file_name" + fileServePath := fmt.Sprintf("%s/:%s/:%s/:%s/:%s", FileServeBasePath, AccountIDKey, MediaTypeKey, MediaSizeKey, FileNameKey) + s.AttachHandler(http.MethodGet, fileServePath, m.ServeFile) return nil } -- cgit v1.2.3