mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[feature] S3: add config flag to proxy S3 media (#1014)
* S3: add config value "proxy" for not redirecting Signed-off-by: Mara Sophie Grosch <littlefox@lf-net.org> * S3: document new config value "proxy" * S3: add new config value "proxy" to test scripts Signed-off-by: Mara Sophie Grosch <littlefox@lf-net.org>
This commit is contained in:
committed by
GitHub
parent
3ce0e33f99
commit
948e90b95a
@@ -93,6 +93,7 @@ type Configuration struct {
|
||||
StorageS3SecretKey string `name:"storage-s3-secret-key" usage:"S3 Secret Key"`
|
||||
StorageS3UseSSL bool `name:"storage-s3-use-ssl" usage:"Use SSL for S3 connections. Only set this to 'false' when testing locally"`
|
||||
StorageS3BucketName string `name:"storage-s3-bucket" usage:"Place blobs in this bucket"`
|
||||
StorageS3Proxy bool `name:"storage-s3-proxy" usage:"Proxy S3 contents through GoToSocial instead of redirecting to a presigned URL"`
|
||||
|
||||
StatusesMaxChars int `name:"statuses-max-chars" usage:"Max permitted characters for posted statuses"`
|
||||
StatusesCWMaxChars int `name:"statuses-cw-max-chars" usage:"Max permitted characters for content/spoiler warnings on statuses"`
|
||||
|
@@ -67,6 +67,7 @@ var Defaults = Configuration{
|
||||
StorageBackend: "local",
|
||||
StorageLocalBasePath: "/gotosocial/storage",
|
||||
StorageS3UseSSL: true,
|
||||
StorageS3Proxy: false,
|
||||
|
||||
StatusesMaxChars: 5000,
|
||||
StatusesCWMaxChars: 100,
|
||||
|
@@ -1095,6 +1095,31 @@ func GetStorageS3BucketName() string { return global.GetStorageS3BucketName() }
|
||||
// SetStorageS3BucketName safely sets the value for global configuration 'StorageS3BucketName' field
|
||||
func SetStorageS3BucketName(v string) { global.SetStorageS3BucketName(v) }
|
||||
|
||||
// GetStorageS3Proxy safely fetches the Configuration value for state's 'StorageS3Proxy' field
|
||||
func (st *ConfigState) GetStorageS3Proxy() (v bool) {
|
||||
st.mutex.Lock()
|
||||
v = st.config.StorageS3Proxy
|
||||
st.mutex.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
// SetStorageS3Proxy safely sets the Configuration value for state's 'StorageS3Proxy' field
|
||||
func (st *ConfigState) SetStorageS3Proxy(v bool) {
|
||||
st.mutex.Lock()
|
||||
defer st.mutex.Unlock()
|
||||
st.config.StorageS3Proxy = v
|
||||
st.reloadToViper()
|
||||
}
|
||||
|
||||
// StorageS3ProxyFlag returns the flag name for the 'StorageS3Proxy' field
|
||||
func StorageS3ProxyFlag() string { return "storage-s3-proxy" }
|
||||
|
||||
// GetStorageS3Proxy safely fetches the value for global configuration 'StorageS3Proxy' field
|
||||
func GetStorageS3Proxy() bool { return global.GetStorageS3Proxy() }
|
||||
|
||||
// SetStorageS3Proxy safely sets the value for global configuration 'StorageS3Proxy' field
|
||||
func SetStorageS3Proxy(v bool) { global.SetStorageS3Proxy(v) }
|
||||
|
||||
// GetStatusesMaxChars safely fetches the Configuration value for state's 'StatusesMaxChars' field
|
||||
func (st *ConfigState) GetStatusesMaxChars() (v int) {
|
||||
st.mutex.Lock()
|
||||
@@ -1844,3 +1869,4 @@ func GetAdvancedRateLimitRequests() int { return global.GetAdvancedRateLimitRequ
|
||||
|
||||
// SetAdvancedRateLimitRequests safely sets the value for global configuration 'AdvancedRateLimitRequests' field
|
||||
func SetAdvancedRateLimitRequests(v int) { global.SetAdvancedRateLimitRequests(v) }
|
||||
|
||||
|
@@ -34,12 +34,14 @@ import (
|
||||
type S3 struct {
|
||||
mc *minio.Client
|
||||
bucket string
|
||||
proxy bool
|
||||
}
|
||||
|
||||
func NewS3(mc *minio.Client, bucket string) *S3 {
|
||||
func NewS3(mc *minio.Client, bucket string, proxy bool) *S3 {
|
||||
return &S3{
|
||||
mc: mc,
|
||||
bucket: bucket,
|
||||
proxy: proxy,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +85,10 @@ func (s *S3) Delete(ctx context.Context, key string) error {
|
||||
}
|
||||
|
||||
func (s *S3) URL(ctx context.Context, key string) *url.URL {
|
||||
if s.proxy {
|
||||
return nil
|
||||
}
|
||||
|
||||
// it's safe to ignore the error here, as we just fall back to fetching the
|
||||
// file if the url request fails
|
||||
url, _ := s.mc.PresignedGetObject(ctx, s.bucket, key, time.Hour, url.Values{
|
||||
|
@@ -59,7 +59,11 @@ func AutoConfig() (Driver, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("creating minio client: %w", err)
|
||||
}
|
||||
return NewS3(mc, config.GetStorageS3BucketName()), nil
|
||||
return NewS3(
|
||||
mc,
|
||||
config.GetStorageS3BucketName(),
|
||||
config.GetStorageS3Proxy(),
|
||||
), nil
|
||||
case "local":
|
||||
basePath := config.GetStorageLocalBasePath()
|
||||
disk, err := storage.OpenDisk(basePath, &storage.DiskConfig{
|
||||
|
Reference in New Issue
Block a user