feat: add STORAGE_ALLOW_LIST env var
This commit is contained in:
@@ -184,9 +184,9 @@ export function reconnectDocReader(addr: string): Promise<ParserEnginesResponse
|
||||
|
||||
export interface StorageEngineConfig {
|
||||
default_provider: string // "local" | "minio" | "cos" | "tos" | "s3" | "oss"
|
||||
local?: { path_prefix: string }
|
||||
minio?: { mode: string; endpoint: string; access_key_id: string; secret_access_key: string; bucket_name: string; use_ssl: boolean; path_prefix: string }
|
||||
cos?: {
|
||||
local: { path_prefix: string }
|
||||
minio: { mode: string; endpoint: string; access_key_id: string; secret_access_key: string; bucket_name: string; use_ssl: boolean; path_prefix: string }
|
||||
cos: {
|
||||
secret_id: string
|
||||
secret_key: string
|
||||
region: string
|
||||
@@ -194,7 +194,7 @@ export interface StorageEngineConfig {
|
||||
app_id: string
|
||||
path_prefix: string
|
||||
}
|
||||
tos?: {
|
||||
tos: {
|
||||
endpoint: string
|
||||
region: string
|
||||
access_key: string
|
||||
@@ -202,7 +202,7 @@ export interface StorageEngineConfig {
|
||||
bucket_name: string
|
||||
path_prefix: string
|
||||
}
|
||||
s3?: {
|
||||
s3: {
|
||||
endpoint: string
|
||||
region: string
|
||||
access_key: string
|
||||
@@ -210,7 +210,7 @@ export interface StorageEngineConfig {
|
||||
bucket_name: string
|
||||
path_prefix: string
|
||||
}
|
||||
oss?: {
|
||||
oss: {
|
||||
endpoint: string
|
||||
region: string
|
||||
access_key: string
|
||||
@@ -225,12 +225,14 @@ export interface StorageEngineConfig {
|
||||
|
||||
export interface StorageEngineStatusItem {
|
||||
name: string
|
||||
allowed?: boolean
|
||||
available: boolean
|
||||
description: string
|
||||
}
|
||||
|
||||
export interface GetStorageEngineStatusResponse {
|
||||
engines: StorageEngineStatusItem[]
|
||||
allowed_providers?: string[]
|
||||
minio_env_available: boolean
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,8 @@
|
||||
>
|
||||
<span class="select-option">
|
||||
<span>{{ opt.label }}</span>
|
||||
<t-tag v-if="opt.disabled" theme="warning" variant="light" size="small">{{ $t('kbSettings.storage.notConfigured') }}</t-tag>
|
||||
<t-tag v-if="opt.disabled && opt.allowed === false" theme="danger" variant="light" size="small">{{ $t('kbSettings.storage.unavailable') }}</t-tag>
|
||||
<t-tag v-else-if="opt.disabled" theme="warning" variant="light" size="small">{{ $t('kbSettings.storage.notConfigured') }}</t-tag>
|
||||
<t-tag v-else-if="opt.available === false" theme="danger" variant="light" size="small">{{ $t('kbSettings.storage.unavailable') }}</t-tag>
|
||||
</span>
|
||||
</t-option>
|
||||
@@ -71,55 +72,64 @@ const localProvider = ref(props.storageProvider || 'local')
|
||||
const loading = ref(true)
|
||||
const engineStatus = ref<StorageEngineStatusItem[]>([])
|
||||
const defaultProvider = ref('local')
|
||||
const allowedProviders = ref<string[]>([])
|
||||
const hasAnyConfig = ref(false)
|
||||
|
||||
const engineOptions = computed(() => {
|
||||
const statusMap: Record<string, boolean> = {}
|
||||
const allowedMap: Record<string, boolean> = {}
|
||||
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 {
|
||||
|
||||
@@ -28,20 +28,15 @@
|
||||
<p class="desc">{{ $t('settings.storage.defaultEngineDesc') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-select v-model="config.default_provider" style="width: 280px;" :placeholder="$t('settings.storage.defaultEngine')">
|
||||
<t-option value="local" :label="$t('settings.storage.engineLocal')" />
|
||||
<t-option value="minio" label="MinIO" />
|
||||
<t-option value="cos" :label="$t('settings.storage.engineCos')" />
|
||||
<t-option value="tos" :label="$t('settings.storage.engineTos')" />
|
||||
<t-option value="s3" label="AWS S3" />
|
||||
<t-option value="oss" :label="$t('settings.storage.engineOss')" />
|
||||
<t-select v-model="config.default_provider" style="width: 280px;" :placeholder="$t('settings.storage.defaultEngine')" :disabled="!hasAllowedProviders">
|
||||
<t-option v-for="opt in providerOptions" :key="opt.value" :value="opt.value" :label="opt.label" :disabled="!opt.allowed" />
|
||||
</t-select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Local -->
|
||||
<div class="engine-section" data-model-type="local">
|
||||
<div v-if="isProviderAllowed('local')" class="engine-section" data-model-type="local">
|
||||
<div class="engine-header">
|
||||
<div class="engine-header-info">
|
||||
<div class="engine-title-row">
|
||||
@@ -64,7 +59,7 @@
|
||||
</div>
|
||||
|
||||
<!-- MinIO -->
|
||||
<div class="engine-section" data-model-type="minio">
|
||||
<div v-if="isProviderAllowed('minio')" class="engine-section" data-model-type="minio">
|
||||
<div class="engine-header">
|
||||
<div class="engine-header-info">
|
||||
<div class="engine-title-row">
|
||||
@@ -202,7 +197,7 @@
|
||||
</div>
|
||||
|
||||
<!-- COS -->
|
||||
<div class="engine-section" data-model-type="cos">
|
||||
<div v-if="isProviderAllowed('cos')" class="engine-section" data-model-type="cos">
|
||||
<div class="engine-header">
|
||||
<div class="engine-header-info">
|
||||
<div class="engine-title-row">
|
||||
@@ -276,7 +271,7 @@
|
||||
</div>
|
||||
|
||||
<!-- TOS -->
|
||||
<div class="engine-section" data-model-type="tos">
|
||||
<div v-if="isProviderAllowed('tos')" class="engine-section" data-model-type="tos">
|
||||
<div class="engine-header">
|
||||
<div class="engine-header-info">
|
||||
<div class="engine-title-row">
|
||||
@@ -350,7 +345,7 @@
|
||||
</div>
|
||||
|
||||
<!-- S3 -->
|
||||
<div class="engine-section" data-model-type="s3">
|
||||
<div v-if="isProviderAllowed('s3')" class="engine-section" data-model-type="s3">
|
||||
<div class="engine-header">
|
||||
<div class="engine-header-info">
|
||||
<div class="engine-title-row">
|
||||
@@ -424,7 +419,7 @@
|
||||
</div>
|
||||
|
||||
<!-- OSS -->
|
||||
<div class="engine-section" data-model-type="oss">
|
||||
<div v-if="isProviderAllowed('oss')" class="engine-section" data-model-type="oss">
|
||||
<div class="engine-header">
|
||||
<div class="engine-header-info">
|
||||
<div class="engine-title-row">
|
||||
@@ -499,7 +494,7 @@
|
||||
|
||||
<!-- Save -->
|
||||
<div class="save-bar">
|
||||
<t-button theme="primary" :loading="saving" @click="onSave">{{ $t('settings.storage.saveConfig') }}</t-button>
|
||||
<t-button theme="primary" :loading="saving" :disabled="!hasAllowedProviders" @click="onSave">{{ $t('settings.storage.saveConfig') }}</t-button>
|
||||
<span v-if="saveMessage" :class="['save-msg', saveSuccess ? 'success' : 'error']">
|
||||
{{ saveMessage }}
|
||||
</span>
|
||||
@@ -567,6 +562,7 @@ const defaultConfig = (): StorageEngineConfig => ({
|
||||
const loading = ref(true)
|
||||
const error = ref('')
|
||||
const config = ref<StorageEngineConfig>(defaultConfig())
|
||||
const allowedProviders = ref<string[] | null>(null)
|
||||
const engineStatus = ref<{ local: boolean; minio: boolean; cos: boolean }>({
|
||||
local: true,
|
||||
minio: false,
|
||||
@@ -590,6 +586,17 @@ const s3CheckResult = ref<{ ok: boolean; message: string } | null>(null)
|
||||
const checkingOss = ref(false)
|
||||
const ossCheckResult = ref<{ ok: boolean; message: string } | null>(null)
|
||||
|
||||
const providerOptions = computed(() => [
|
||||
{ value: 'local', label: t('settings.storage.engineLocal'), allowed: isProviderAllowed('local') },
|
||||
{ value: 'minio', label: 'MinIO', allowed: isProviderAllowed('minio') },
|
||||
{ value: 'cos', label: t('settings.storage.engineCos'), allowed: isProviderAllowed('cos') },
|
||||
{ value: 'tos', label: t('settings.storage.engineTos'), allowed: isProviderAllowed('tos') },
|
||||
{ value: 's3', label: 'AWS S3', allowed: isProviderAllowed('s3') },
|
||||
{ value: 'oss', label: t('settings.storage.engineOss'), allowed: isProviderAllowed('oss') },
|
||||
])
|
||||
|
||||
const hasAllowedProviders = computed(() => (allowedProviders.value?.length ?? 0) > 0)
|
||||
|
||||
const minioAvailable = computed(() => {
|
||||
if (config.value.minio?.mode === 'remote') {
|
||||
return !!(config.value.minio.endpoint && config.value.minio.access_key_id && config.value.minio.secret_access_key)
|
||||
@@ -597,6 +604,17 @@ const minioAvailable = computed(() => {
|
||||
return minioEnvAvailable.value
|
||||
})
|
||||
|
||||
function isProviderAllowed(provider: string) {
|
||||
if (allowedProviders.value === null) return true
|
||||
return allowedProviders.value.includes(provider)
|
||||
}
|
||||
|
||||
function ensureAllowedDefaultProvider() {
|
||||
if (isProviderAllowed(config.value.default_provider)) return
|
||||
const fallback = allowedProviders.value?.[0] || 'local'
|
||||
config.value.default_provider = fallback
|
||||
}
|
||||
|
||||
async function loadConfig() {
|
||||
try {
|
||||
const res = await getStorageEngineConfig()
|
||||
@@ -670,6 +688,9 @@ async function loadStatus() {
|
||||
try {
|
||||
const res = await getStorageEngineStatus()
|
||||
const engines = res?.data?.engines ?? []
|
||||
allowedProviders.value = res?.data?.allowed_providers?.length
|
||||
? res.data.allowed_providers
|
||||
: engines.filter(e => e.allowed !== false).map(e => e.name)
|
||||
const status = { local: true, minio: false, cos: true }
|
||||
for (const e of engines) {
|
||||
if (e.name === 'local') status.local = e.available
|
||||
@@ -680,6 +701,7 @@ async function loadStatus() {
|
||||
minioEnvAvailable.value = res?.data?.minio_env_available ?? false
|
||||
} catch {
|
||||
engineStatus.value = { local: true, minio: false, cos: true }
|
||||
allowedProviders.value = ['local', 'minio', 'cos', 'tos', 's3', 'oss']
|
||||
minioEnvAvailable.value = false
|
||||
}
|
||||
}
|
||||
@@ -704,6 +726,7 @@ async function loadAll() {
|
||||
error.value = ''
|
||||
try {
|
||||
await Promise.all([loadConfig(), loadStatus()])
|
||||
ensureAllowedDefaultProvider()
|
||||
if (minioEnvAvailable.value) loadMinioBuckets()
|
||||
} catch (e: unknown) {
|
||||
error.value = e instanceof Error ? e.message : t('settings.storage.loadFailed')
|
||||
|
||||
Reference in New Issue
Block a user