diff --git a/lib/image-delivery.ts b/lib/image-delivery.ts index e9d56ef35..db3bc49bc 100644 --- a/lib/image-delivery.ts +++ b/lib/image-delivery.ts @@ -42,6 +42,28 @@ function isAliyunOssImageHost(hostname: string): boolean { return normalized.endsWith(".aliyuncs.com") && normalized.includes(".oss-"); } +function isTrustedDirectStorageImageHost(hostname: string): boolean { + const normalized = hostname.trim().toLowerCase(); + return ( + normalized === "yybb.top" || + normalized.endsWith(".qiniucs.com") || + normalized.endsWith(".qiniudn.com") || + normalized.endsWith(".clouddn.com") || + normalized.endsWith(".qbox.me") + ); +} + +function resolveTrustedDirectStorageDisplayUrl(url: string): string | null { + try { + const target = new URL(url); + return isTrustedDirectStorageImageHost(target.hostname) + ? target.toString() + : null; + } catch { + return null; + } +} + function resolveAliyunOssDisplayUrl( url: string, options: Pick @@ -94,6 +116,11 @@ export function buildImageProxyUrl(url: string, options: ImageProxyOptions = {}) return source; } + const trustedDirectStorageUrl = resolveTrustedDirectStorageDisplayUrl(source); + if (trustedDirectStorageUrl) { + return trustedDirectStorageUrl; + } + if (options.delivery !== "proxy") { const directDisplayUrl = resolveAliyunOssDisplayUrl(source, options); if (directDisplayUrl) {