From ce722897f1abefc9cbdec94895cfc6becd1bbbcb Mon Sep 17 00:00:00 2001 From: Yaodong Yu <2814461814@qq.com> Date: Fri, 4 Nov 2022 21:08:39 +0800 Subject: [PATCH] feat: support prefix path for storage files (#1258) --- object/provider.go | 1 + object/storage.go | 4 ++-- web/src/ProviderEditPage.js | 10 ++++++++++ web/src/locales/de/data.json | 10 ++++++---- web/src/locales/en/data.json | 10 ++++++---- web/src/locales/fr/data.json | 10 ++++++---- web/src/locales/ja/data.json | 10 ++++++---- web/src/locales/ko/data.json | 10 ++++++---- web/src/locales/ru/data.json | 10 ++++++---- web/src/locales/zh/data.json | 10 ++++++---- 10 files changed, 55 insertions(+), 30 deletions(-) diff --git a/object/provider.go b/object/provider.go index 8b3d6261..ef30894e 100644 --- a/object/provider.go +++ b/object/provider.go @@ -60,6 +60,7 @@ type Provider struct { IntranetEndpoint string `xorm:"varchar(100)" json:"intranetEndpoint"` Domain string `xorm:"varchar(100)" json:"domain"` Bucket string `xorm:"varchar(100)" json:"bucket"` + PathPrefix string `xorm:"varchar(100)" json:"pathPrefix"` Metadata string `xorm:"mediumtext" json:"metadata"` IdP string `xorm:"mediumtext" json:"idP"` diff --git a/object/storage.go b/object/storage.go index bb4a29e0..d2095342 100644 --- a/object/storage.go +++ b/object/storage.go @@ -55,7 +55,7 @@ func escapePath(path string) string { } func getUploadFileUrl(provider *Provider, fullFilePath string, hasTimestamp bool) (string, string) { - escapedPath := escapePath(fullFilePath) + escapedPath := util.UrlJoin(provider.PathPrefix, escapePath(fullFilePath)) objectKey := util.UrlJoin(util.GetUrlPath(provider.Domain), escapedPath) host := "" @@ -70,7 +70,7 @@ func getUploadFileUrl(provider *Provider, fullFilePath string, hasTimestamp bool host = util.UrlJoin(provider.Domain, "/files") } if provider.Type == "Azure Blob" { - host = fmt.Sprintf("%s/%s", host, provider.Bucket) + host = util.UrlJoin(host, provider.Bucket) } fileUrl := util.UrlJoin(host, escapePath(objectKey)) diff --git a/web/src/ProviderEditPage.js b/web/src/ProviderEditPage.js index dd006e0c..ea04cc79 100644 --- a/web/src/ProviderEditPage.js +++ b/web/src/ProviderEditPage.js @@ -469,6 +469,16 @@ class ProviderEditPage extends React.Component { }} /> + + + {Setting.getLabel(i18next.t("provider:Path prefix"), i18next.t("provider:The prefix path of the file - Tooltip"))} : + + + { + this.updateProviderField("pathPrefix", e.target.value); + }} /> + + {Setting.getLabel(i18next.t("provider:Domain"), i18next.t("provider:Domain - Tooltip"))} : diff --git a/web/src/locales/de/data.json b/web/src/locales/de/data.json index 0327498d..3183bc48 100644 --- a/web/src/locales/de/data.json +++ b/web/src/locales/de/data.json @@ -13,6 +13,7 @@ "Sync": "Sync" }, "application": { + "Always": "Always", "Auto signin": "Auto signin", "Auto signin - Tooltip": "Auto signin - Tooltip", "Background URL": "Background URL", @@ -43,6 +44,7 @@ "Grant types - Tooltip": "Grant types - Tooltip", "Left": "Left", "New Application": "New Application", + "None": "None", "Password ON": "Passwort AN", "Password ON - Tooltip": "Whether to allow password login", "Please select a HTML file": "Bitte wählen Sie eine HTML-Datei", @@ -53,6 +55,7 @@ "Refresh token expire": "Aktualisierungs-Token läuft ab", "Refresh token expire - Tooltip": "Aktualisierungs-Token läuft ab - Tooltip", "Right": "Right", + "Rule": "Rule", "SAML metadata": "SAML metadata", "SAML metadata - Tooltip": "SAML metadata - Tooltip", "SAML metadata URL copied to clipboard successfully": "SAML metadata URL copied to clipboard successfully", @@ -67,10 +70,7 @@ "Token expire": "Token läuft ab", "Token expire - Tooltip": "Token läuft ab - Tooltip", "Token format": "Token-Format", - "Token format - Tooltip": "Token-Format - Tooltip", - "Rule": "Rule", - "None": "None", - "Always": "Always" + "Token format - Tooltip": "Token-Format - Tooltip" }, "cert": { "Bit size": "Bitgröße", @@ -491,6 +491,7 @@ "New Provider": "New Provider", "Parse": "Parse", "Parse Metadata successfully": "Metadaten erfolgreich analysieren", + "Path prefix": "Path prefix", "Port": "Port", "Port - Tooltip": "Unique string-style identifier", "Provider URL": "Provider-URL", @@ -535,6 +536,7 @@ "Test Connection": "Test Smtp Connection", "Test Email": "Test email config", "Test Email - Tooltip": "Email Address", + "The prefix path of the file - Tooltip": "The prefix path of the file - Tooltip", "Token URL": "Token URL", "Token URL - Tooltip": "Token URL - Tooltip", "Type": "Typ", diff --git a/web/src/locales/en/data.json b/web/src/locales/en/data.json index f825219d..15a1da9d 100644 --- a/web/src/locales/en/data.json +++ b/web/src/locales/en/data.json @@ -13,6 +13,7 @@ "Sync": "Sync" }, "application": { + "Always": "Always", "Auto signin": "Auto signin", "Auto signin - Tooltip": "Auto signin - Tooltip", "Background URL": "Background URL", @@ -43,6 +44,7 @@ "Grant types - Tooltip": "Grant types - Tooltip", "Left": "Left", "New Application": "New Application", + "None": "None", "Password ON": "Password ON", "Password ON - Tooltip": "Password ON - Tooltip", "Please select a HTML file": "Please select a HTML file", @@ -53,6 +55,7 @@ "Refresh token expire": "Refresh token expire", "Refresh token expire - Tooltip": "Refresh token expire - Tooltip", "Right": "Right", + "Rule": "Rule", "SAML metadata": "SAML metadata", "SAML metadata - Tooltip": "SAML metadata - Tooltip", "SAML metadata URL copied to clipboard successfully": "SAML metadata URL copied to clipboard successfully", @@ -67,10 +70,7 @@ "Token expire": "Token expire", "Token expire - Tooltip": "Token expire - Tooltip", "Token format": "Token format", - "Token format - Tooltip": "Token format - Tooltip", - "Rule": "Rule", - "None": "None", - "Always": "Always" + "Token format - Tooltip": "Token format - Tooltip" }, "cert": { "Bit size": "Bit size", @@ -491,6 +491,7 @@ "New Provider": "New Provider", "Parse": "Parse", "Parse Metadata successfully": "Parse Metadata successfully", + "Path prefix": "Path prefix", "Port": "Port", "Port - Tooltip": "Port - Tooltip", "Provider URL": "Provider URL", @@ -535,6 +536,7 @@ "Test Connection": "Test Connection", "Test Email": "Test Email", "Test Email - Tooltip": "Test Email - Tooltip", + "The prefix path of the file - Tooltip": "The prefix path of the file - Tooltip", "Token URL": "Token URL", "Token URL - Tooltip": "Token URL - Tooltip", "Type": "Type", diff --git a/web/src/locales/fr/data.json b/web/src/locales/fr/data.json index 6477551e..144f0050 100644 --- a/web/src/locales/fr/data.json +++ b/web/src/locales/fr/data.json @@ -13,6 +13,7 @@ "Sync": "Sync" }, "application": { + "Always": "Always", "Auto signin": "Auto signin", "Auto signin - Tooltip": "Auto signin - Tooltip", "Background URL": "Background URL", @@ -43,6 +44,7 @@ "Grant types - Tooltip": "Grant types - Tooltip", "Left": "Left", "New Application": "New Application", + "None": "None", "Password ON": "Mot de passe activé", "Password ON - Tooltip": "Whether to allow password login", "Please select a HTML file": "Veuillez sélectionner un fichier HTML", @@ -53,6 +55,7 @@ "Refresh token expire": "Expiration du jeton d'actualisation", "Refresh token expire - Tooltip": "Expiration du jeton d'actualisation - infobulle", "Right": "Right", + "Rule": "Rule", "SAML metadata": "SAML metadata", "SAML metadata - Tooltip": "SAML metadata - Tooltip", "SAML metadata URL copied to clipboard successfully": "SAML metadata URL copied to clipboard successfully", @@ -67,10 +70,7 @@ "Token expire": "Expiration du jeton", "Token expire - Tooltip": "Expiration du jeton - Info-bulle", "Token format": "Format du jeton", - "Token format - Tooltip": "Format du jeton - infobulle", - "Rule": "Rule", - "None": "None", - "Always": "Always" + "Token format - Tooltip": "Format du jeton - infobulle" }, "cert": { "Bit size": "Taille du bit", @@ -491,6 +491,7 @@ "New Provider": "New Provider", "Parse": "Parse", "Parse Metadata successfully": "Analyse des métadonnées réussie", + "Path prefix": "Path prefix", "Port": "Port", "Port - Tooltip": "Unique string-style identifier", "Provider URL": "URL du fournisseur", @@ -535,6 +536,7 @@ "Test Connection": "Test Smtp Connection", "Test Email": "Test email config", "Test Email - Tooltip": "Email Address", + "The prefix path of the file - Tooltip": "The prefix path of the file - Tooltip", "Token URL": "Token URL", "Token URL - Tooltip": "Token URL - Tooltip", "Type": "Type de texte", diff --git a/web/src/locales/ja/data.json b/web/src/locales/ja/data.json index 52a949e4..82c6248a 100644 --- a/web/src/locales/ja/data.json +++ b/web/src/locales/ja/data.json @@ -13,6 +13,7 @@ "Sync": "Sync" }, "application": { + "Always": "Always", "Auto signin": "Auto signin", "Auto signin - Tooltip": "Auto signin - Tooltip", "Background URL": "Background URL", @@ -43,6 +44,7 @@ "Grant types - Tooltip": "Grant types - Tooltip", "Left": "Left", "New Application": "New Application", + "None": "None", "Password ON": "パスワードON", "Password ON - Tooltip": "Whether to allow password login", "Please select a HTML file": "HTMLファイルを選択してください", @@ -53,6 +55,7 @@ "Refresh token expire": "トークンの更新の期限が切れます", "Refresh token expire - Tooltip": "トークンの有効期限を更新する - ツールチップ", "Right": "Right", + "Rule": "Rule", "SAML metadata": "SAML metadata", "SAML metadata - Tooltip": "SAML metadata - Tooltip", "SAML metadata URL copied to clipboard successfully": "SAML metadata URL copied to clipboard successfully", @@ -67,10 +70,7 @@ "Token expire": "トークンの有効期限", "Token expire - Tooltip": "トークンの有効期限 - ツールチップ", "Token format": "トークンのフォーマット", - "Token format - Tooltip": "トークンフォーマット - ツールチップ", - "Rule": "Rule", - "None": "None", - "Always": "Always" + "Token format - Tooltip": "トークンフォーマット - ツールチップ" }, "cert": { "Bit size": "ビットサイズ", @@ -491,6 +491,7 @@ "New Provider": "New Provider", "Parse": "Parse", "Parse Metadata successfully": "メタデータの解析に成功", + "Path prefix": "Path prefix", "Port": "ポート", "Port - Tooltip": "Unique string-style identifier", "Provider URL": "プロバイダー URL", @@ -535,6 +536,7 @@ "Test Connection": "Test Smtp Connection", "Test Email": "Test email config", "Test Email - Tooltip": "Email Address", + "The prefix path of the file - Tooltip": "The prefix path of the file - Tooltip", "Token URL": "Token URL", "Token URL - Tooltip": "Token URL - Tooltip", "Type": "タイプ", diff --git a/web/src/locales/ko/data.json b/web/src/locales/ko/data.json index 00edabba..8e0a1276 100644 --- a/web/src/locales/ko/data.json +++ b/web/src/locales/ko/data.json @@ -13,6 +13,7 @@ "Sync": "Sync" }, "application": { + "Always": "Always", "Auto signin": "Auto signin", "Auto signin - Tooltip": "Auto signin - Tooltip", "Background URL": "Background URL", @@ -43,6 +44,7 @@ "Grant types - Tooltip": "Grant types - Tooltip", "Left": "Left", "New Application": "New Application", + "None": "None", "Password ON": "Password ON", "Password ON - Tooltip": "Whether to allow password login", "Please select a HTML file": "Please select a HTML file", @@ -53,6 +55,7 @@ "Refresh token expire": "Refresh token expire", "Refresh token expire - Tooltip": "Refresh token expire - Tooltip", "Right": "Right", + "Rule": "Rule", "SAML metadata": "SAML metadata", "SAML metadata - Tooltip": "SAML metadata - Tooltip", "SAML metadata URL copied to clipboard successfully": "SAML metadata URL copied to clipboard successfully", @@ -67,10 +70,7 @@ "Token expire": "Token expire", "Token expire - Tooltip": "Token expire - Tooltip", "Token format": "Token format", - "Token format - Tooltip": "Token format - Tooltip", - "Rule": "Rule", - "None": "None", - "Always": "Always" + "Token format - Tooltip": "Token format - Tooltip" }, "cert": { "Bit size": "Bit size", @@ -491,6 +491,7 @@ "New Provider": "New Provider", "Parse": "Parse", "Parse Metadata successfully": "Parse Metadata successfully", + "Path prefix": "Path prefix", "Port": "Port", "Port - Tooltip": "Unique string-style identifier", "Provider URL": "Provider URL", @@ -535,6 +536,7 @@ "Test Connection": "Test Smtp Connection", "Test Email": "Test email config", "Test Email - Tooltip": "Email Address", + "The prefix path of the file - Tooltip": "The prefix path of the file - Tooltip", "Token URL": "Token URL", "Token URL - Tooltip": "Token URL - Tooltip", "Type": "Type", diff --git a/web/src/locales/ru/data.json b/web/src/locales/ru/data.json index fb2d4362..f9333f9c 100644 --- a/web/src/locales/ru/data.json +++ b/web/src/locales/ru/data.json @@ -13,6 +13,7 @@ "Sync": "Sync" }, "application": { + "Always": "Always", "Auto signin": "Auto signin", "Auto signin - Tooltip": "Auto signin - Tooltip", "Background URL": "Background URL", @@ -43,6 +44,7 @@ "Grant types - Tooltip": "Виды грантов - Подсказка", "Left": "Left", "New Application": "Новое приложение", + "None": "None", "Password ON": "Пароль ВКЛ", "Password ON - Tooltip": "Whether to allow password login", "Please select a HTML file": "Пожалуйста, выберите HTML-файл", @@ -53,6 +55,7 @@ "Refresh token expire": "Срок действия обновления токена истекает", "Refresh token expire - Tooltip": "Срок обновления токена истекает - Подсказка", "Right": "Right", + "Rule": "правило", "SAML metadata": "Метаданные SAML", "SAML metadata - Tooltip": "Метаданные SAML - Подсказка", "SAML metadata URL copied to clipboard successfully": "Адрес метаданных SAML скопирован в буфер обмена", @@ -67,10 +70,7 @@ "Token expire": "Токен истекает", "Token expire - Tooltip": "Истек токен - Подсказка", "Token format": "Формат токена", - "Token format - Tooltip": "Формат токена - Подсказка", - "Rule": "правило", - "None": "None", - "Always": "Always" + "Token format - Tooltip": "Формат токена - Подсказка" }, "cert": { "Bit size": "Размер бита", @@ -491,6 +491,7 @@ "New Provider": "New Provider", "Parse": "Parse", "Parse Metadata successfully": "Анализ метаданных успешно завершен", + "Path prefix": "Path prefix", "Port": "Порт", "Port - Tooltip": "Unique string-style identifier", "Provider URL": "URL провайдера", @@ -535,6 +536,7 @@ "Test Connection": "Test Smtp Connection", "Test Email": "Test email config", "Test Email - Tooltip": "Email Address", + "The prefix path of the file - Tooltip": "The prefix path of the file - Tooltip", "Token URL": "Token URL", "Token URL - Tooltip": "Token URL - Tooltip", "Type": "Тип", diff --git a/web/src/locales/zh/data.json b/web/src/locales/zh/data.json index 568752a1..f84ec7cd 100644 --- a/web/src/locales/zh/data.json +++ b/web/src/locales/zh/data.json @@ -13,6 +13,7 @@ "Sync": "同步" }, "application": { + "Always": "始终开启", "Auto signin": "启用自动登录", "Auto signin - Tooltip": "当Casdoor存在已登录会话时,自动采用该会话进行应用端的登录", "Background URL": "背景图URL", @@ -43,6 +44,7 @@ "Grant types - Tooltip": "选择允许哪些OAuth协议中的Grant types", "Left": "居左", "New Application": "添加应用", + "None": "关闭", "Password ON": "开启密码", "Password ON - Tooltip": "是否允许密码登录", "Please select a HTML file": "请选择一个HTML文件", @@ -53,6 +55,7 @@ "Refresh token expire": "Refresh Token过期", "Refresh token expire - Tooltip": "Refresh Token过期时间", "Right": "居右", + "Rule": "规则", "SAML metadata": "SAML元数据", "SAML metadata - Tooltip": "SAML协议的元数据(Metadata)信息", "SAML metadata URL copied to clipboard successfully": "SAML元数据URL已成功复制到剪贴板", @@ -67,10 +70,7 @@ "Token expire": "Access Token过期", "Token expire - Tooltip": "Access Token过期时间", "Token format": "Access Token格式", - "Token format - Tooltip": "Access Token格式", - "Rule": "规则", - "None": "关闭", - "Always": "始终开启" + "Token format - Tooltip": "Access Token格式" }, "cert": { "Bit size": "位大小", @@ -491,6 +491,7 @@ "New Provider": "添加提供商", "Parse": "Parse", "Parse Metadata successfully": "解析元数据成功", + "Path prefix": "路径前缀", "Port": "端口", "Port - Tooltip": "端口号", "Provider URL": "提供商URL", @@ -535,6 +536,7 @@ "Test Connection": "测试SMTP连接", "Test Email": "测试Email配置", "Test Email - Tooltip": "邮箱地址", + "The prefix path of the file - Tooltip": "文件的路径前缀 - 工具提示", "Token URL": "Token URL", "Token URL - Tooltip": "Token URL - 工具提示", "Type": "类型",