feat(obs): 支持华为云obs存储

This commit is contained in:
Li Xianggang
2026-05-18 18:54:57 +08:00
committed by lyingbug
parent 5cee0d0921
commit b3dbf86bf5
21 changed files with 626 additions and 30 deletions
+1 -1
View File
@@ -117,7 +117,7 @@ export interface KBModelConfigRequest {
multimodal: {
enabled: boolean
}
/** 存储引擎选择:"local" | "minio" | "cos",影响文档上传与文档内图片存储 */
/** 存储引擎选择:"local" | "minio" | "cos" | "obs" 等,影响文档上传与文档内图片存储 */
storageProvider?: string
nodeExtract: {
enabled: boolean
+11 -2
View File
@@ -118,7 +118,7 @@ export function reconnectDocReader(addr: string): Promise<ParserEnginesResponse
// ---- 存储引擎配置(租户级,供文档/图片存储与 docreader 使用) ----
export interface StorageEngineConfig {
default_provider: string // "local" | "minio" | "cos" | "tos" | "s3" | "oss" | "ks3"
default_provider: string // "local" | "minio" | "cos" | "tos" | "s3" | "oss" | "ks3" | "obs"
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: {
@@ -164,6 +164,14 @@ export interface StorageEngineConfig {
bucket_name: string
path_prefix: string
}
obs: {
endpoint: string
region: string
access_key: string
secret_key: string
bucket_name: string
path_prefix: string
}
}
export interface StorageEngineStatusItem {
@@ -192,13 +200,14 @@ export function getStorageEngineStatus(): Promise<{ data: GetStorageEngineStatus
}
export interface StorageCheckRequest {
provider: string // "minio" | "cos" | "tos" | "s3" | "oss" | "ks3"
provider: string // "minio" | "cos" | "tos" | "s3" | "oss" | "ks3" | "obs"
minio?: StorageEngineConfig['minio']
cos?: StorageEngineConfig['cos']
tos?: StorageEngineConfig['tos']
s3?: StorageEngineConfig['s3']
oss?: StorageEngineConfig['oss']
ks3?: StorageEngineConfig['ks3']
obs?: StorageEngineConfig['obs']
}
export interface StorageCheckResponse {
+10
View File
@@ -832,6 +832,13 @@ export default {
ks3EndpointPlaceholder: 'e.g. ks3-cn-beijing.ksyuncs.com',
ks3RegionPlaceholder: 'e.g. BEIJING',
engineKs3: 'Kingsoft Cloud KS3',
obsTitle: 'Huawei Cloud OBS',
obsDesc: 'Huawei Cloud Object Storage Service (OBS), suitable for public cloud deployment.',
obsAccessKeyPlaceholder: 'Huawei Cloud Access Key',
obsSecretKeyPlaceholder: 'Huawei Cloud Secret Key',
obsEndpointPlaceholder: 'e.g. obs.cn-north-4.myhuaweicloud.com',
obsRegionPlaceholder: 'e.g. cn-north-4',
engineObs: 'Huawei Cloud OBS',
ossTitle: 'Alibaba Cloud OSS',
ossDesc: 'Alibaba Cloud Object Storage Service (OSS), suitable for public cloud deployment.',
ossAccessKeyPlaceholder: 'Alibaba Cloud Access Key',
@@ -849,6 +856,7 @@ export default {
tos: 'Volcengine TOS',
oss: 'Alibaba Cloud OSS',
ks3: 'Kingsoft Cloud KS3',
obs: 'Huawei Cloud OBS',
},
},
webSearchSettings: {
@@ -3747,6 +3755,8 @@ export default {
engineOssDesc: 'Alibaba Cloud Object Storage Service, for public cloud deployment',
engineKs3: 'Kingsoft Cloud KS3',
engineKs3Desc: 'Kingsoft Cloud Object Storage Service, for public cloud deployment',
engineObs: 'Huawei Cloud OBS',
engineObsDesc: 'Huawei Cloud Object Storage Service, for public cloud deployment',
},
parser: {
title: 'Parser Engine',
+10
View File
@@ -695,6 +695,13 @@ export default {
ks3EndpointPlaceholder: 'e.g. ks3-cn-beijing.ksyuncs.com',
ks3RegionPlaceholder: 'e.g. BEIJING',
engineKs3: 'Kingsoft Cloud KS3',
obsTitle: 'Huawei Cloud OBS',
obsDesc: 'Huawei Cloud 오브젝트 스토리지 서비스(OBS), 퍼블릭 클라우드 배포에 적합합니다.',
obsAccessKeyPlaceholder: 'Huawei Cloud Access Key',
obsSecretKeyPlaceholder: 'Huawei Cloud Secret Key',
obsEndpointPlaceholder: 'e.g. obs.cn-north-4.myhuaweicloud.com',
obsRegionPlaceholder: 'e.g. cn-north-4',
engineObs: 'Huawei Cloud OBS',
ossTitle: 'Alibaba Cloud OSS',
ossDesc: 'Alibaba Cloud 오브젝트 스토리지 서비스(OSS), 퍼블릭 클라우드 배포에 적합합니다.',
ossAccessKeyPlaceholder: 'Alibaba Cloud Access Key',
@@ -712,6 +719,7 @@ export default {
tos: 'Volcengine TOS',
oss: 'Alibaba Cloud OSS',
ks3: 'Kingsoft Cloud KS3',
obs: 'Huawei Cloud OBS',
},
},
webSearchSettings: {
@@ -3810,6 +3818,8 @@ export default {
engineOssDesc: 'Alibaba Cloud 오브젝트 스토리지, 퍼블릭 클라우드 배포에 적합',
engineKs3: 'Kingsoft Cloud KS3',
engineKs3Desc: 'Kingsoft Cloud 오브젝트 스토리지, 퍼블릭 클라우드 배포에 적합',
engineObs: 'Huawei Cloud OBS',
engineObsDesc: 'Huawei Cloud 오브젝트 스토리지, 퍼블릭 클라우드 배포에 적합',
},
parser: {
title: '파서 엔진',
+10
View File
@@ -797,6 +797,13 @@ export default {
ks3EndpointPlaceholder: 'e.g. ks3-cn-beijing.ksyuncs.com',
ks3RegionPlaceholder: 'e.g. BEIJING',
engineKs3: 'Kingsoft Cloud KS3',
obsTitle: 'Huawei Cloud OBS',
obsDesc: 'Объектное хранилище Huawei Cloud (OBS), подходит для публичного облака.',
obsAccessKeyPlaceholder: 'Huawei Cloud Access Key',
obsSecretKeyPlaceholder: 'Huawei Cloud Secret Key',
obsEndpointPlaceholder: 'e.g. obs.cn-north-4.myhuaweicloud.com',
obsRegionPlaceholder: 'e.g. cn-north-4',
engineObs: 'Huawei Cloud OBS',
ossTitle: 'Alibaba Cloud OSS',
ossDesc: 'Объектное хранилище Alibaba Cloud (OSS), подходит для публичного облака.',
ossAccessKeyPlaceholder: 'Alibaba Cloud Access Key',
@@ -814,6 +821,7 @@ export default {
tos: 'Volcengine TOS',
oss: 'Alibaba Cloud OSS',
ks3: 'Kingsoft Cloud KS3',
obs: 'Huawei Cloud OBS',
}
},
webSearchSettings: {
@@ -3388,6 +3396,8 @@ export default {
engineOssDesc: 'Объектное хранилище Alibaba Cloud, для публичного облака',
engineKs3: 'Kingsoft Cloud KS3',
engineKs3Desc: 'Объектное хранилище Kingsoft Cloud, для публичного облака',
engineObs: 'Huawei Cloud OBS',
engineObsDesc: 'Объектное хранилище Huawei Cloud, для публичного облака',
},
parser: {
title: 'Парсер',
+10
View File
@@ -691,6 +691,13 @@ export default {
ks3EndpointPlaceholder: "e.g. ks3-cn-beijing.ksyuncs.com",
ks3RegionPlaceholder: "e.g. BEIJING",
engineKs3: "金山云 KS3",
obsTitle: "华为云 OBS",
obsDesc: "华为云对象存储服务(OBS),适合公有云部署。",
obsAccessKeyPlaceholder: "华为云 Access Key",
obsSecretKeyPlaceholder: "华为云 Secret Key",
obsEndpointPlaceholder: "e.g. obs.cn-north-4.myhuaweicloud.com",
obsRegionPlaceholder: "e.g. cn-north-4",
engineObs: "华为云 OBS",
ossTitle: "阿里云 OSS",
ossDesc: "阿里云对象存储服务(OSS),适合公有云部署。",
ossAccessKeyPlaceholder: "阿里云 Access Key",
@@ -708,6 +715,7 @@ export default {
tos: "火山引擎 TOS",
oss: "阿里云 OSS",
ks3: "金山云 KS3",
obs: "华为云 OBS",
},
},
webSearchSettings: {
@@ -3742,6 +3750,8 @@ export default {
engineOssDesc: "阿里云对象存储,适合公有云部署",
engineKs3: "金山云 KS3",
engineKs3Desc: "金山云对象存储,适合公有云部署",
engineObs: "华为云 OBS",
engineObsDesc: "华为云对象存储,适合公有云部署",
},
parser: {
title: "解析引擎",
+5 -5
View File
@@ -46,7 +46,7 @@ const DOMPurifyConfig = {
],
USE_PROFILES: { html: true, svg: true, mathMl: true },
// 允许的协议
ALLOWED_URI_REGEXP: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|(?:local|minio|cos|tos|s3|oss|ks3):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i,
ALLOWED_URI_REGEXP: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|(?:local|minio|cos|tos|s3|oss|ks3|obs):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i,
// 禁止的标签和属性
FORBID_TAGS: ['script', 'style', 'object', 'embed', 'form', 'input', 'button'],
FORBID_ATTR: ['onerror', 'onload', 'onclick', 'onmouseover', 'onfocus', 'onblur'],
@@ -124,7 +124,7 @@ function protectProviderImageSrcInHTML(html: string): string {
.replace(/&amp;/g, '&')
.replace(/&quot;/g, '"');
return html.replace(
/<img\b([^>]*?)\ssrc=(["'])(local|minio|cos|tos|s3|oss|ks3):(?:\/\/|&#x2f;&#x2f;|&#47;&#47;)([^"']+)\2([^>]*)>/gi,
/<img\b([^>]*?)\ssrc=(["'])(local|minio|cos|tos|s3|oss|ks3|obs):(?:\/\/|&#x2f;&#x2f;|&#47;&#47;)([^"']+)\2([^>]*)>/gi,
(_m, before, quote, provider, restPathRaw, after) => {
const restPath = decodeProviderURL(restPathRaw);
const protectedSrc = `${provider}://${restPath}`;
@@ -178,7 +178,7 @@ export function isValidURL(url: string): boolean {
}
// 允许 provider:// 形式,由前端后续鉴权拉取并替换为 blob URL
if (/^(local|minio|cos|tos|s3|oss|ks3):\/\/\S+$/i.test(trimmed)) {
if (/^(local|minio|cos|tos|s3|oss|ks3|obs):\/\/\S+$/i.test(trimmed)) {
return true;
}
@@ -301,7 +301,7 @@ export async function hydrateProtectedFileImages(root: ParentNode | null | undef
}
const images = root.querySelectorAll<HTMLImageElement>(
'img[data-protected-src], img[src^="local://"], img[src^="minio://"], img[src^="cos://"], img[src^="tos://"], img[src^="s3://"], img[src^="oss://"], img[src^="ks3://"]',
'img[data-protected-src], img[src^="local://"], img[src^="minio://"], img[src^="cos://"], img[src^="tos://"], img[src^="s3://"], img[src^="oss://"], img[src^="ks3://"], img[src^="obs://"]',
);
if (!images.length) {
return;
@@ -321,7 +321,7 @@ export async function hydrateProtectedFileImages(root: ParentNode | null | undef
}
img.dataset.authHydrated = '1';
const isProviderScheme = /^(local|minio|cos|tos|s3|oss|ks3):\/\//.test(sourceURL);
const isProviderScheme = /^(local|minio|cos|tos|s3|oss|ks3|obs):\/\//.test(sourceURL);
const requestURL = isProviderScheme
? `/files?${new URLSearchParams({ file_path: sourceURL }).toString()}`
: sourceURL;
@@ -139,6 +139,14 @@ const engineOptions = computed(() => {
available: statusMap.ks3,
disabled: allowedMap.ks3 === false || statusMap.ks3 === false,
},
{
value: 'obs',
label: t('kbSettings.storage.engineObs'),
desc: t('kbSettings.storage.engineObsDesc'),
allowed: allowedMap.obs !== false,
available: statusMap.obs,
disabled: allowedMap.obs === false || statusMap.obs === false,
},
]
})
@@ -179,7 +187,7 @@ async function load() {
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 || d?.oss?.bucket_name || d?.ks3?.bucket_name)
hasAnyConfig.value = !!(d?.local?.path_prefix || d?.minio?.bucket_name || d?.cos?.bucket_name || d?.tos?.bucket_name || d?.s3?.bucket_name || d?.oss?.bucket_name || d?.ks3?.bucket_name || d?.obs?.bucket_name)
if (!localProvider.value || localProvider.value === '') {
localProvider.value = defaultProvider.value
emit('update:storageProvider', localProvider.value)
@@ -135,6 +135,18 @@
</div>
<p class="engine-card-desc">{{ $t('settings.storage.ks3Desc') }}</p>
</div>
<div
v-if="isProviderAllowed('obs')"
:class="['engine-card', { active: drawerVisible && currentEngine === 'obs' }]"
@click="openDrawer('obs')"
>
<div class="engine-card-header">
<h3>{{ $t('settings.storage.obsTitle') }}</h3>
<t-tag theme="success" variant="light" size="small">{{ $t('settings.storage.configurable') }}</t-tag>
</div>
<p class="engine-card-desc">{{ $t('settings.storage.obsDesc') }}</p>
</div>
</div>
</template>
@@ -449,6 +461,67 @@
</div>
</template>
<template v-else-if="currentEngine === 'obs'">
<div class="engine-info-block">
<p class="engine-desc">
{{ $t('settings.storage.obsDesc') }}
<a class="engine-link" href="https://obs.huaweicloud.com/" target="_blank" rel="noopener">{{ $t('settings.storage.console') }} ↗</a>
<a class="engine-link" href="https://support.huaweicloud.com/obs/" target="_blank" rel="noopener">{{ $t('settings.storage.docs') }} ↗</a>
</p>
</div>
<div class="engine-form">
<div class="form-item">
<label class="form-label">Endpoint</label>
<t-input
v-model="config.obs.endpoint"
:placeholder="$t('settings.storage.obsEndpointPlaceholder')"
clearable
/>
</div>
<div class="form-item">
<label class="form-label">Region</label>
<t-input
v-model="config.obs.region"
:placeholder="$t('settings.storage.obsRegionPlaceholder')"
clearable
/>
</div>
<div class="form-item">
<label class="form-label">Access Key</label>
<t-input
v-model="config.obs.access_key"
:placeholder="$t('settings.storage.obsAccessKeyPlaceholder')"
clearable
/>
</div>
<div class="form-item">
<label class="form-label">Secret Key</label>
<t-input
v-model="config.obs.secret_key"
type="password"
:placeholder="$t('settings.storage.obsSecretKeyPlaceholder')"
clearable
/>
</div>
<div class="form-item">
<label class="form-label">{{ $t('settings.storage.bucketName') }}</label>
<t-input
v-model="config.obs.bucket_name"
:placeholder="$t('settings.storage.bucketPlaceholder')"
clearable
/>
</div>
<div class="form-item">
<label class="form-label">{{ $t('settings.storage.pathPrefix') }}</label>
<t-input
v-model="config.obs.path_prefix"
:placeholder="$t('settings.storage.prefixPlaceholder')"
clearable
/>
</div>
</div>
</template>
<div class="form-item" v-if="currentEngine && currentEngine !== 'local'">
<label class="form-label">{{ $t('settings.storage.testConnection') }}</label>
<div class="api-test-section">
@@ -513,6 +586,14 @@ const defaultConfig = (): StorageEngineConfig => ({
bucket_name: '',
path_prefix: '',
},
obs: {
endpoint: '',
region: '',
access_key: '',
secret_key: '',
bucket_name: '',
path_prefix: '',
},
})
const loading = ref(true)
@@ -537,6 +618,8 @@ const checkingOss = ref(false)
const ossCheckResult = ref<{ ok: boolean; message: string } | null>(null)
const checkingKs3 = ref(false)
const ks3CheckResult = ref<{ ok: boolean; message: string } | null>(null)
const checkingObs = ref(false)
const obsCheckResult = ref<{ ok: boolean; message: string } | null>(null)
const drawerVisible = ref(false)
const currentEngine = ref<string | null>(null)
@@ -549,6 +632,7 @@ const providerOptions = computed(() => [
{ value: 's3', label: 'AWS S3', allowed: isProviderAllowed('s3') },
{ value: 'oss', label: t('settings.storage.engineOss'), allowed: isProviderAllowed('oss') },
{ value: 'ks3', label: t('settings.storage.engineKs3'), allowed: isProviderAllowed('ks3') },
{ value: 'obs', label: t('settings.storage.engineObs'), allowed: isProviderAllowed('obs') },
])
const hasAllowedProviders = computed(() => (allowedProviders.value?.length ?? 0) > 0)
@@ -567,6 +651,8 @@ const currentCheckState = computed(() => {
return { loading: checkingOss.value, result: ossCheckResult.value, onCheck: onCheckOss }
case 'ks3':
return { loading: checkingKs3.value, result: ks3CheckResult.value, onCheck: onCheckKs3 }
case 'obs':
return { loading: checkingObs.value, result: obsCheckResult.value, onCheck: onCheckObs }
default:
return { loading: false, result: null, onCheck: () => undefined }
}
@@ -582,6 +668,7 @@ const drawerTitle = computed(() => {
s3: t('settings.storage.s3Title'),
oss: t('settings.storage.ossTitle'),
ks3: t('settings.storage.ks3Title'),
obs: t('settings.storage.obsTitle'),
}
return titles[currentEngine.value] || currentEngine.value
})
@@ -614,6 +701,7 @@ function openDrawer(engine: string) {
s3CheckResult.value = null
ossCheckResult.value = null
ks3CheckResult.value = null
obsCheckResult.value = null
}
async function loadConfig() {
@@ -688,6 +776,16 @@ async function loadConfig() {
path_prefix: d.ks3.path_prefix || '',
}
: defaultConfig().ks3,
obs: d.obs
? {
endpoint: d.obs.endpoint || '',
region: d.obs.region || '',
access_key: d.obs.access_key || '',
secret_key: d.obs.secret_key || '',
bucket_name: d.obs.bucket_name || '',
path_prefix: d.obs.path_prefix || '',
}
: defaultConfig().obs,
}
}
} catch {
@@ -787,6 +885,14 @@ function buildPayload(): StorageEngineConfig {
bucket_name: (config.value.ks3?.bucket_name || '').trim(),
path_prefix: (config.value.ks3?.path_prefix || '').trim(),
},
obs: {
endpoint: (config.value.obs?.endpoint || '').trim(),
region: (config.value.obs?.region || '').trim(),
access_key: (config.value.obs?.access_key || '').trim(),
secret_key: (config.value.obs?.secret_key || '').trim(),
bucket_name: (config.value.obs?.bucket_name || '').trim(),
path_prefix: (config.value.obs?.path_prefix || '').trim(),
},
}
}
@@ -897,6 +1003,20 @@ async function onCheckKs3() {
}
}
async function onCheckObs() {
checkingObs.value = true
obsCheckResult.value = null
try {
const payload = buildPayload()
const res = await checkStorageEngine({ provider: 'obs', obs: payload.obs })
obsCheckResult.value = res?.data ?? { ok: false, message: t('settings.storage.unknownError') }
} catch (e: unknown) {
obsCheckResult.value = { ok: false, message: e instanceof Error ? e.message : t('settings.storage.requestFailed') }
} finally {
checkingObs.value = false
}
}
onMounted(loadAll)
</script>