bypass proxy for direct storage images
This commit is contained in:
parent
8acf1f60ec
commit
05b21707c1
@ -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<ImageProxyOptions, "width" | "quality" | "format">
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user