feat: 接入可选字体包同源渲染链
This commit is contained in:
@@ -52,3 +52,33 @@ export function parseThemeResourceUrl(requestUrl: string) {
|
||||
assetPath: assetSegments.join("/")
|
||||
};
|
||||
}
|
||||
|
||||
export function parseFontPackResourceUrl(requestUrl: string) {
|
||||
const url = new URL(requestUrl);
|
||||
if (url.protocol !== "mdpdf:" || url.host !== "font-pack") {
|
||||
return undefined;
|
||||
}
|
||||
let segments: string[];
|
||||
try {
|
||||
segments = url.pathname
|
||||
.split("/")
|
||||
.filter(Boolean)
|
||||
.map((segment) => decodeURIComponent(segment));
|
||||
} catch {
|
||||
throw new Error("字体包资源地址无效");
|
||||
}
|
||||
const [packId, packVersion, faceId, kind, ...extra] = segments;
|
||||
if (
|
||||
!packId ||
|
||||
!/^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(packId) ||
|
||||
!packVersion ||
|
||||
!/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u.test(packVersion) ||
|
||||
!faceId ||
|
||||
!/^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(faceId) ||
|
||||
kind !== "web" ||
|
||||
extra.length > 0
|
||||
) {
|
||||
throw new Error("字体包资源地址无效");
|
||||
}
|
||||
return { packId, packVersion, faceId, kind } as const;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user