mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
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
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user