fix(storage): 强化外部图片导入与 Skill 异常引导

This commit is contained in:
yuzhe
2026-07-22 19:34:36 +08:00
parent 3bfb481c71
commit 69cfd0b51d
12 changed files with 112 additions and 31 deletions

View File

@@ -110,6 +110,10 @@ async function assertPublicRemote(url: URL): Promise<void> {
}
}
export async function assertPublicHttpUrl(value: string): Promise<void> {
await assertPublicRemote(new URL(value));
}
function assertRemoteUrlShape(url: URL): void {
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password) {
throw new StorageImportError(400, '图片地址必须是公开的 HTTP/HTTPS URL');
@@ -207,7 +211,7 @@ export async function storeExternalImageUrl(value: string): Promise<StoredExtern
const config = await getActiveStorageConfig();
if (!config) throw new StorageImportError(409, '未启用腾讯云 COS 配置,无法导入外部图片 URL');
const source = new URL(value);
assertRemoteUrlShape(source);
await assertPublicRemote(source);
if (configuredOrigins(config).has(source.origin)) {
return { url: source.toString(), width: 0, height: 0, storageProvider: 'tencent_cos', storageKey: source.pathname.replace(/^\/+/, '') };
}