diff --git a/.env.example b/.env.example index a593ae2df..7af813012 100644 --- a/.env.example +++ b/.env.example @@ -123,6 +123,9 @@ DB_DRIVER=postgres # 向量存储类型(postgres/elasticsearch_v7/elasticsearch_v8/qdrant/milvus/weaviate) RETRIEVE_DRIVER=postgres +# 允许用户使用哪些文件存储类型,使用逗号分隔,留空则允许所有类型的存储 +# STORAGE_ALLOW_LIST=local,minio,cos,tos,s3 + # 文件存储类型(local/minio/cos/tos/s3) STORAGE_TYPE=local diff --git a/frontend/src/api/system/index.ts b/frontend/src/api/system/index.ts index 431bcb604..e0aa5269b 100644 --- a/frontend/src/api/system/index.ts +++ b/frontend/src/api/system/index.ts @@ -170,9 +170,9 @@ export function reconnectDocReader(addr: string): Promise {{ opt.label }} - {{ $t('kbSettings.storage.notConfigured') }} + {{ $t('kbSettings.storage.unavailable') }} + {{ $t('kbSettings.storage.notConfigured') }} {{ $t('kbSettings.storage.unavailable') }} @@ -71,55 +72,64 @@ const localProvider = ref(props.storageProvider || 'local') const loading = ref(true) const engineStatus = ref([]) const defaultProvider = ref('local') +const allowedProviders = ref([]) const hasAnyConfig = ref(false) const engineOptions = computed(() => { const statusMap: Record = {} + const allowedMap: Record = {} for (const e of engineStatus.value) { statusMap[e.name] = e.available + allowedMap[e.name] = e.allowed !== false } return [ { value: 'local', label: t('kbSettings.storage.engineLocal'), desc: t('kbSettings.storage.engineLocalDesc'), + allowed: allowedMap.local !== false, available: statusMap.local !== false, - disabled: false, + disabled: allowedMap.local === false, }, { value: 'minio', label: 'MinIO', desc: t('kbSettings.storage.engineMinioDesc'), + allowed: allowedMap.minio !== false, available: statusMap.minio, - disabled: statusMap.minio === false, + disabled: allowedMap.minio === false || statusMap.minio === false, }, { value: 'cos', label: t('kbSettings.storage.engineCos'), desc: t('kbSettings.storage.engineCosDesc'), + allowed: allowedMap.cos !== false, available: statusMap.cos, - disabled: statusMap.cos === false, + disabled: allowedMap.cos === false || statusMap.cos === false, }, { value: 'tos', label: t('kbSettings.storage.engineTos'), desc: t('kbSettings.storage.engineTosDesc'), + allowed: allowedMap.tos !== false, available: statusMap.tos, - disabled: statusMap.tos === false, + disabled: allowedMap.tos === false || statusMap.tos === false, }, { value: 's3', label: t('kbSettings.storage.engineS3'), desc: t('kbSettings.storage.engineS3Desc'), + allowed: allowedMap.s3 !== false, available: statusMap.s3, - disabled: statusMap.s3 === false, + disabled: allowedMap.s3 === false || statusMap.s3 === false, }, { value: 'oss', label: t('kbSettings.storage.engineOss'), desc: t('kbSettings.storage.engineOssDesc'), + allowed: allowedMap.oss !== false, available: statusMap.oss, - disabled: statusMap.oss === false, + disabled: allowedMap.oss === false || statusMap.oss === false, }, ] }) @@ -136,6 +146,14 @@ function handleChange() { emit('update:storageProvider', localProvider.value) } +function ensureAllowedProvider() { + const current = engineOptions.value.find(o => o.value === localProvider.value && !o.disabled) + if (current) return + const fallback = engineOptions.value.find(o => !o.disabled)?.value || defaultProvider.value || 'local' + localProvider.value = fallback + emit('update:storageProvider', localProvider.value) +} + function goToStorageSettings() { uiStore.closeKBEditor?.() uiStore.openSettings?.('storage') @@ -150,6 +168,7 @@ async function load() { ]) const engines = statusRes?.data?.engines ?? [] engineStatus.value = engines + allowedProviders.value = statusRes?.data?.allowed_providers ?? [] defaultProvider.value = configRes?.data?.default_provider || 'local' const d = configRes?.data hasAnyConfig.value = !!(d?.local?.path_prefix || d?.minio?.bucket_name || d?.cos?.bucket_name || d?.tos?.bucket_name || d?.s3?.bucket_name) @@ -157,6 +176,7 @@ async function load() { localProvider.value = defaultProvider.value emit('update:storageProvider', localProvider.value) } + ensureAllowedProvider() } catch { engineStatus.value = [] } finally { diff --git a/frontend/src/views/settings/StorageEngineSettings.vue b/frontend/src/views/settings/StorageEngineSettings.vue index ecb18259b..4c7f57a31 100644 --- a/frontend/src/views/settings/StorageEngineSettings.vue +++ b/frontend/src/views/settings/StorageEngineSettings.vue @@ -32,14 +32,16 @@ v-model="config.default_provider" style="width: 280px;" :placeholder="$t('settings.storage.defaultEngine')" + :disabled="!hasAllowedProviders" @change="onSaveDefaultEngine" > - - - - - - + {{ saveMessage }} @@ -49,8 +51,11 @@
- -
+

{{ $t('settings.storage.localTitle') }}

{{ $t('settings.storage.available') }} @@ -58,8 +63,11 @@

{{ $t('settings.storage.localDesc') }}

- -
+

MinIO

{{ $t('settings.storage.available') }} @@ -68,8 +76,11 @@

{{ $t('settings.storage.minioDesc') }}

- -
+

{{ $t('settings.storage.cosTitle') }}

{{ $t('settings.storage.configurable') }} @@ -77,8 +88,11 @@

{{ $t('settings.storage.cosDesc') }}

- -
+

{{ $t('settings.storage.tosTitle') }}

{{ $t('settings.storage.configurable') }} @@ -86,8 +100,11 @@

{{ $t('settings.storage.tosDesc') }}

- -
+

{{ $t('settings.storage.s3Title') }}

{{ $t('settings.storage.configurable') }} @@ -95,8 +112,11 @@

{{ $t('settings.storage.s3Desc') }}

- -
+

{{ $t('settings.storage.ossTitle') }}

{{ $t('settings.storage.configurable') }} @@ -106,7 +126,6 @@
-
- - - - - - +
@@ -511,13 +402,13 @@