mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-10 05:38:07 -06:00
[feature] Object store custom URL (S3) (#3046)
* tweaks * boobs * fix variable name + typo --------- Co-authored-by: tobi <tobi.smethurst@protonmail.com>
This commit is contained in:
parent
26022c2733
commit
43519324b3
8 changed files with 158 additions and 9 deletions
|
|
@ -110,6 +110,7 @@ type Configuration struct {
|
|||
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"`
|
||||
StorageS3RedirectURL string `name:"storage-s3-redirect-url" usage:"Custom URL to use for redirecting S3 media links. If set, this will be used instead of the S3 bucket URL."`
|
||||
|
||||
StatusesMaxChars int `name:"statuses-max-chars" usage:"Max permitted characters for posted statuses, including content warning"`
|
||||
StatusesPollMaxOptions int `name:"statuses-poll-max-options" usage:"Max amount of options permitted on a poll"`
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ var Defaults = Configuration{
|
|||
StorageLocalBasePath: "/gotosocial/storage",
|
||||
StorageS3UseSSL: true,
|
||||
StorageS3Proxy: false,
|
||||
StorageS3RedirectURL: "",
|
||||
|
||||
StatusesMaxChars: 5000,
|
||||
StatusesPollMaxOptions: 6,
|
||||
|
|
|
|||
|
|
@ -1500,6 +1500,31 @@ func GetStorageS3Proxy() bool { return global.GetStorageS3Proxy() }
|
|||
// SetStorageS3Proxy safely sets the value for global configuration 'StorageS3Proxy' field
|
||||
func SetStorageS3Proxy(v bool) { global.SetStorageS3Proxy(v) }
|
||||
|
||||
// GetStorageS3RedirectURL safely fetches the Configuration value for state's 'StorageS3RedirectURL' field
|
||||
func (st *ConfigState) GetStorageS3RedirectURL() (v string) {
|
||||
st.mutex.RLock()
|
||||
v = st.config.StorageS3RedirectURL
|
||||
st.mutex.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
// SetStorageS3RedirectURL safely sets the Configuration value for state's 'StorageS3RedirectURL' field
|
||||
func (st *ConfigState) SetStorageS3RedirectURL(v string) {
|
||||
st.mutex.Lock()
|
||||
defer st.mutex.Unlock()
|
||||
st.config.StorageS3RedirectURL = v
|
||||
st.reloadToViper()
|
||||
}
|
||||
|
||||
// StorageS3RedirectURLFlag returns the flag name for the 'StorageS3RedirectURL' field
|
||||
func StorageS3RedirectURLFlag() string { return "storage-s3-redirect-url" }
|
||||
|
||||
// GetStorageS3RedirectURL safely fetches the value for global configuration 'StorageS3RedirectURL' field
|
||||
func GetStorageS3RedirectURL() string { return global.GetStorageS3RedirectURL() }
|
||||
|
||||
// SetStorageS3RedirectURL safely sets the value for global configuration 'StorageS3RedirectURL' field
|
||||
func SetStorageS3RedirectURL(v string) { global.SetStorageS3RedirectURL(v) }
|
||||
|
||||
// GetStatusesMaxChars safely fetches the Configuration value for state's 'StatusesMaxChars' field
|
||||
func (st *ConfigState) GetStatusesMaxChars() (v int) {
|
||||
st.mutex.RLock()
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ package config
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
|
|
@ -118,6 +120,28 @@ func Validate() error {
|
|||
errf("%s must be set", WebAssetBaseDirFlag())
|
||||
}
|
||||
|
||||
// `storage-s3-redirect-url`
|
||||
if s3RedirectURL := GetStorageS3RedirectURL(); s3RedirectURL != "" {
|
||||
if strings.HasSuffix(s3RedirectURL, "/") {
|
||||
errf(
|
||||
"%s must not end with a trailing slash",
|
||||
StorageS3RedirectURLFlag(),
|
||||
)
|
||||
}
|
||||
|
||||
if url, err := url.Parse(s3RedirectURL); err != nil {
|
||||
errf(
|
||||
"%s invalid: %w",
|
||||
StorageS3RedirectURLFlag(), err,
|
||||
)
|
||||
} else if url.Scheme != "https" && url.Scheme != "http" {
|
||||
errf(
|
||||
"%s scheme must be https or http",
|
||||
StorageS3RedirectURLFlag(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Custom / LE TLS settings.
|
||||
//
|
||||
// Only one of custom certs or LE can be set,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue