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/media/processicon.go | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'internal/media/processicon.go') diff --git a/internal/media/processicon.go b/internal/media/processicon.go index 5f4f8b138..c377033fc 100644 --- a/internal/media/processicon.go +++ b/internal/media/processicon.go @@ -24,10 +24,9 @@ import ( "strings" "time" - "github.com/spf13/viper" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/id" + "github.com/superseriousbusiness/gotosocial/internal/uris" ) func (mh *mediaHandler) processHeaderOrAvi(imageBytes []byte, contentType string, mediaType Type, accountID string, remoteURL string) (*gtsmodel.MediaAttachment, error) { @@ -35,9 +34,9 @@ func (mh *mediaHandler) processHeaderOrAvi(imageBytes []byte, contentType string var isAvatar bool switch mediaType { - case Header: + case TypeHeader: isHeader = true - case Avatar: + case TypeAvatar: isAvatar = true default: return nil, errors.New("header or avatar not selected") @@ -81,23 +80,16 @@ func (mh *mediaHandler) processHeaderOrAvi(imageBytes []byte, contentType string return nil, err } - keys := config.Keys - serveProtocol := viper.GetString(keys.StorageServeProtocol) - serveHost := viper.GetString(keys.StorageServeHost) - serveBasePath := viper.GetString(keys.StorageServeBasePath) - - URLbase := fmt.Sprintf("%s://%s%s", serveProtocol, serveHost, serveBasePath) - originalURL := fmt.Sprintf("%s/%s/%s/original/%s.%s", URLbase, accountID, mediaType, newMediaID, extension) - smallURL := fmt.Sprintf("%s/%s/%s/small/%s.%s", URLbase, accountID, mediaType, newMediaID, extension) - + originalURL := uris.GenerateURIForAttachment(accountID, string(mediaType), string(SizeOriginal), newMediaID, extension) + smallURL := uris.GenerateURIForAttachment(accountID, string(mediaType), string(SizeSmall), newMediaID, extension) // we store the original... - originalPath := fmt.Sprintf("%s/%s/%s/%s.%s", accountID, mediaType, Original, newMediaID, extension) + originalPath := fmt.Sprintf("%s/%s/%s/%s.%s", accountID, mediaType, SizeOriginal, newMediaID, extension) if err := mh.storage.Put(originalPath, original.image); err != nil { return nil, fmt.Errorf("storage error: %s", err) } // and a thumbnail... - smallPath := fmt.Sprintf("%s/%s/%s/%s.%s", accountID, mediaType, Small, newMediaID, extension) + smallPath := fmt.Sprintf("%s/%s/%s/%s.%s", accountID, mediaType, SizeSmall, newMediaID, extension) if err := mh.storage.Put(smallPath, small.image); err != nil { return nil, fmt.Errorf("storage error: %s", err) } -- cgit v1.2.3