Skip to content

Commit

Permalink
Add support for custom public S3 URLs. Closes #505.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Jan 15, 2022
1 parent 7955a4f commit 64d2c5a
Show file tree
Hide file tree
Showing 20 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmd/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
14 changes: 10 additions & 4 deletions frontend/src/views/settings/media.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
</b-field>
</div>
</div>

<div class="columns">
<div class="column is-3">
<b-field :label="$t('settings.media.s3.uploadExpiry')"
Expand All @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions i18n/cs-cz.json
Original file line number Diff line number Diff line change
Expand Up @@ -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í",
Expand Down
2 changes: 2 additions & 0 deletions i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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é",
Expand Down
2 changes: 2 additions & 0 deletions i18n/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions i18n/ml.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "അപ്ലോഡിന്റെ കാലാവധി",
Expand Down
2 changes: 2 additions & 0 deletions i18n/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions i18n/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions i18n/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions i18n/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "Срок жизни выгрузки",
Expand Down
2 changes: 2 additions & 0 deletions i18n/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions internal/media/providers/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
}
3 changes: 2 additions & 1 deletion internal/migrations/v2.1.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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"'),
Expand Down

0 comments on commit 64d2c5a

Please sign in to comment.