fix(storage): 强化外部图片导入与 Skill 异常引导
This commit is contained in:
@@ -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(/^\/+/, '') };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user