Add support for custom public S3 URLs. Closes #505.

This commit is contained in:
Kailash Nadh 2022-01-15 21:20:32 +05:30
parent 7955a4fa27
commit 64d2c5aeb9
20 changed files with 49 additions and 5 deletions

View file

@ -45,6 +45,7 @@ type settings struct {
UploadFilesystemUploadPath string `json:"upload.filesystem.upload_path"`
UploadFilesystemUploadURI string `json:"upload.filesystem.upload_uri"`
UploadS3URL string `json:"upload.s3.url"`
UploadS3PublicURL string `json:"upload.s3.public_url"`
UploadS3AwsAccessKeyID string `json:"upload.s3.aws_access_key_id"`
UploadS3AwsDefaultRegion string `json:"upload.s3.aws_default_region"`
UploadS3AwsSecretAccessKey string `json:"upload.s3.aws_secret_access_key,omitempty"`

View file

@ -81,6 +81,7 @@
</b-field>
</div>
</div>
<div class="columns">
<div class="column is-3">
<b-field :label="$t('settings.media.s3.uploadExpiry')"
@ -91,13 +92,18 @@
placeholder="14d" :pattern="regDuration" :maxlength="10" />
</b-field>
</div>
<div class="column">
<b-field :label="$t('settings.media.s3.url')"
label-position="on-border"
<div class="column is-9">
<b-field :label="$t('settings.media.s3.url')" label-position="on-border"
:message="$t('settings.media.s3.urlHelp')" expanded>
<b-input v-model="data['upload.s3.url']"
name="upload.s3.url" :disabled="!data['upload.s3.bucket']" required
placeholder="https://s3.region.amazonaws.com" :maxlength="200" />
placeholder="https://s3.$region.amazonaws.com" :maxlength="200" />
</b-field>
<b-field :label="$t('settings.media.s3.publicURL')" label-position="on-border" expanded>
<b-input v-model="data['upload.s3.public_url']"
:message="$t('settings.media.s3.publicURLHelp')"
name="upload.s3.public_url" :disabled="!data['upload.s3.bucket']"
placeholder="https://files.yourdomain.com" :maxlength="200" />
</b-field>
</div>
</div>

View file

@ -377,6 +377,8 @@
"settings.media.s3.bucketTypePrivate": "Soukromý",
"settings.media.s3.bucketTypePublic": "Veřejný",
"settings.media.s3.key": "Přístupový klíč AWS",
"settings.media.s3.publicURL": "Custom public URL (optional)",
"settings.media.s3.publicURLHelp": "Custom S3 domain to use for image links instead of the default S3 backend URL.",
"settings.media.s3.region": "Oblast",
"settings.media.s3.secret": "Přístupový tajný údaj AWS",
"settings.media.s3.uploadExpiry": "Uplynulá platnost odeslání",

View file

@ -377,6 +377,8 @@
"settings.media.s3.bucketTypePrivate": "Privat",
"settings.media.s3.bucketTypePublic": "Öffentlich",
"settings.media.s3.key": "AWS Access Key (Zugriffsschlüssel)",
"settings.media.s3.publicURL": "Custom public URL (optional)",
"settings.media.s3.publicURLHelp": "Custom S3 domain to use for image links instead of the default S3 backend URL.",
"settings.media.s3.region": "Region",
"settings.media.s3.secret": "AWS Access Secret",
"settings.media.s3.uploadExpiry": "Upload Ablaufdatum",

View file

@ -377,6 +377,8 @@
"settings.media.s3.bucketTypePrivate": "Private",
"settings.media.s3.bucketTypePublic": "Public",
"settings.media.s3.key": "AWS access key",
"settings.media.s3.publicURL": "Custom public URL (optional)",
"settings.media.s3.publicURLHelp": "Custom S3 domain to use for image links instead of the default S3 backend URL.",
"settings.media.s3.region": "Region",
"settings.media.s3.secret": "AWS access secret",
"settings.media.s3.uploadExpiry": "Upload expiry",

View file

@ -377,6 +377,8 @@
"settings.media.s3.bucketTypePrivate": "Privado",
"settings.media.s3.bucketTypePublic": "Público",
"settings.media.s3.key": "Llave de acceso a AWS (key)",
"settings.media.s3.publicURL": "Custom public URL (optional)",
"settings.media.s3.publicURLHelp": "Custom S3 domain to use for image links instead of the default S3 backend URL.",
"settings.media.s3.region": "Región",
"settings.media.s3.secret": "Secreto de acceso a AWS (secret)",
"settings.media.s3.uploadExpiry": "Expiración de carga",

View file

@ -377,6 +377,8 @@
"settings.media.s3.bucketTypePrivate": "Privé",
"settings.media.s3.bucketTypePublic": "Public",
"settings.media.s3.key": "Clé d'accès AWS",
"settings.media.s3.publicURL": "Custom public URL (optional)",
"settings.media.s3.publicURLHelp": "Custom S3 domain to use for image links instead of the default S3 backend URL.",
"settings.media.s3.region": "Région",
"settings.media.s3.secret": "Mot de passe d'accès AWS",
"settings.media.s3.uploadExpiry": "Durée de validité",

View file

@ -377,6 +377,8 @@
"settings.media.s3.bucketTypePrivate": "Privát",
"settings.media.s3.bucketTypePublic": "Nyilvános",
"settings.media.s3.key": "AWS access key",
"settings.media.s3.publicURL": "Custom public URL (optional)",
"settings.media.s3.publicURLHelp": "Custom S3 domain to use for image links instead of the default S3 backend URL.",
"settings.media.s3.region": "Régió",
"settings.media.s3.secret": "AWS access secret",
"settings.media.s3.uploadExpiry": "Feltöltés lejárata",

View file

@ -377,6 +377,8 @@
"settings.media.s3.bucketTypePrivate": "Privato",
"settings.media.s3.bucketTypePublic": "Pubblico",
"settings.media.s3.key": "Chiave d'accesso AWS",
"settings.media.s3.publicURL": "Custom public URL (optional)",
"settings.media.s3.publicURLHelp": "Custom S3 domain to use for image links instead of the default S3 backend URL.",
"settings.media.s3.region": "Regione",
"settings.media.s3.secret": "Accesso segreto AWS",
"settings.media.s3.uploadExpiry": "Caricamento scaduto",

View file

@ -377,6 +377,8 @@
"settings.media.s3.bucketTypePrivate": "സ്വകാര്യമായ",
"settings.media.s3.bucketTypePublic": "പൊതുവായ",
"settings.media.s3.key": "AWS പ്രവേശന വാക്യം",
"settings.media.s3.publicURL": "Custom public URL (optional)",
"settings.media.s3.publicURLHelp": "Custom S3 domain to use for image links instead of the default S3 backend URL.",
"settings.media.s3.region": "മേഖല",
"settings.media.s3.secret": "AWS പ്രവേശന രഹസ്യം",
"settings.media.s3.uploadExpiry": "അപ്ലോഡിന്റെ കാലാവധി",

View file

@ -377,6 +377,8 @@
"settings.media.s3.bucketTypePrivate": "Privé",
"settings.media.s3.bucketTypePublic": "Publiek",
"settings.media.s3.key": "AWS access key",
"settings.media.s3.publicURL": "Custom public URL (optional)",
"settings.media.s3.publicURLHelp": "Custom S3 domain to use for image links instead of the default S3 backend URL.",
"settings.media.s3.region": "Regio",
"settings.media.s3.secret": "AWS access secret",
"settings.media.s3.uploadExpiry": "Upload vervaldatum",

View file

@ -377,6 +377,8 @@
"settings.media.s3.bucketTypePrivate": "Prywatny",
"settings.media.s3.bucketTypePublic": "Publiczny",
"settings.media.s3.key": "Klucz dostępu AWS",
"settings.media.s3.publicURL": "Custom public URL (optional)",
"settings.media.s3.publicURLHelp": "Custom S3 domain to use for image links instead of the default S3 backend URL.",
"settings.media.s3.region": "Region",
"settings.media.s3.secret": "Sekret dostępu AWS",
"settings.media.s3.uploadExpiry": "Wygaśnięcie przesyłania",

View file

@ -377,6 +377,8 @@
"settings.media.s3.bucketTypePrivate": "Privado",
"settings.media.s3.bucketTypePublic": "Público",
"settings.media.s3.key": "Chave de acesso AWS",
"settings.media.s3.publicURL": "Custom public URL (optional)",
"settings.media.s3.publicURLHelp": "Custom S3 domain to use for image links instead of the default S3 backend URL.",
"settings.media.s3.region": "Região",
"settings.media.s3.secret": "Segredo de acesso AWS",
"settings.media.s3.uploadExpiry": "Expiração do arquivo enviado",

View file

@ -377,6 +377,8 @@
"settings.media.s3.bucketTypePrivate": "Privado",
"settings.media.s3.bucketTypePublic": "Público",
"settings.media.s3.key": "Chave de acesso AWS",
"settings.media.s3.publicURL": "Custom public URL (optional)",
"settings.media.s3.publicURLHelp": "Custom S3 domain to use for image links instead of the default S3 backend URL.",
"settings.media.s3.region": "Região",
"settings.media.s3.secret": "Segredo de acesso AWS",
"settings.media.s3.uploadExpiry": "Validade do upload",

View file

@ -377,6 +377,8 @@
"settings.media.s3.bucketTypePrivate": "Privat",
"settings.media.s3.bucketTypePublic": "Public",
"settings.media.s3.key": "Cheia de acces AWS",
"settings.media.s3.publicURL": "Custom public URL (optional)",
"settings.media.s3.publicURLHelp": "Custom S3 domain to use for image links instead of the default S3 backend URL.",
"settings.media.s3.region": "Regiune",
"settings.media.s3.secret": "Secret de acces AWS",
"settings.media.s3.uploadExpiry": "Expirarea încărcării",

View file

@ -377,6 +377,8 @@
"settings.media.s3.bucketTypePrivate": "Приватный",
"settings.media.s3.bucketTypePublic": "Публичный",
"settings.media.s3.key": "Ключ доступа AWS",
"settings.media.s3.publicURL": "Custom public URL (optional)",
"settings.media.s3.publicURLHelp": "Custom S3 domain to use for image links instead of the default S3 backend URL.",
"settings.media.s3.region": "Регион",
"settings.media.s3.secret": "Секретаня фраза AWS",
"settings.media.s3.uploadExpiry": "Срок жизни выгрузки",

View file

@ -377,6 +377,8 @@
"settings.media.s3.bucketTypePrivate": "Özel",
"settings.media.s3.bucketTypePublic": "Erişime açık",
"settings.media.s3.key": "AWS erişim anahtarı",
"settings.media.s3.publicURL": "Custom public URL (optional)",
"settings.media.s3.publicURLHelp": "Custom S3 domain to use for image links instead of the default S3 backend URL.",
"settings.media.s3.region": "Bölge",
"settings.media.s3.secret": "AWS erişim şifresi(secret)",
"settings.media.s3.uploadExpiry": "Yükleme sona erme",

View file

@ -13,6 +13,7 @@ import (
// Opt represents AWS S3 specific params
type Opt struct {
URL string `koanf:"url"`
PublicURL string `koanf:"public_url"`
AccessKey string `koanf:"aws_access_key_id"`
SecretKey string `koanf:"aws_secret_access_key"`
Region string `koanf:"aws_default_region"`
@ -119,5 +120,9 @@ func (c *Client) makeBucketPath(name string) string {
}
func (c *Client) makeFileURL(name string) string {
if c.opts.PublicURL != "" {
return c.opts.PublicURL + "/" + c.makeBucketPath(name)
}
return c.opts.URL + "/" + c.opts.Bucket + "/" + c.makeBucketPath(name)
}

View file

@ -14,7 +14,8 @@ func V2_1_0(db *sqlx.DB, fs stuffbin.FileSystem, ko *koanf.Koanf) error {
('appearance.admin.custom_css', '""'),
('appearance.admin.custom_js', '""'),
('appearance.public.custom_css', '""'),
('appearance.public.custom_js', '""')
('appearance.public.custom_js', '""'),
('upload.s3.public_url', '""')
ON CONFLICT DO NOTHING;
`); err != nil {
return err

View file

@ -199,6 +199,7 @@ INSERT INTO settings (key, value) VALUES
('upload.filesystem.upload_path', '"uploads"'),
('upload.filesystem.upload_uri', '"/uploads"'),
('upload.s3.url', '"https://ap-south-1.s3.amazonaws.com"'),
('upload.s3.public_url', '""'),
('upload.s3.aws_access_key_id', '""'),
('upload.s3.aws_secret_access_key', '""'),
('upload.s3.aws_default_region', '"ap-south-1"'),