feat: 接入可选字体包同源渲染链
This commit is contained in:
+43
-2
@@ -17,7 +17,8 @@ import {
|
||||
DocxThemeTokenService,
|
||||
createApplicationService,
|
||||
readDocxExportRuntimeLimits,
|
||||
type ApplicationService
|
||||
type ApplicationService,
|
||||
type ApplicationServiceOptions
|
||||
} from "@md-to-pdf/application";
|
||||
import {
|
||||
PandocDocxConverter,
|
||||
@@ -88,6 +89,7 @@ export interface BuildAppOptions {
|
||||
"getCapability" | "generate" | "close"
|
||||
>;
|
||||
docxMediaAdapter?: ServerDocxMediaCaptureAdapter;
|
||||
fontPacks?: NonNullable<ApplicationServiceOptions["fontPacks"]>;
|
||||
}
|
||||
|
||||
function milliseconds(value: number) {
|
||||
@@ -161,7 +163,8 @@ export function buildApp(options: BuildAppOptions = {}) {
|
||||
bundledRoot: resolve(projectRoot, "themes"),
|
||||
localRoot:
|
||||
options.localThemeRoot ?? resolve(projectRoot, ".local", "themes"),
|
||||
onWarning: (message) => app.log.warn(message)
|
||||
onWarning: (message) => app.log.warn(message),
|
||||
...(options.fontPacks ? { fontPacks: options.fontPacks } : {})
|
||||
});
|
||||
const pdfGenerator =
|
||||
options.pdfGenerator ?? createPdfGenerator();
|
||||
@@ -301,6 +304,44 @@ export function buildApp(options: BuildAppOptions = {}) {
|
||||
}
|
||||
);
|
||||
|
||||
app.get<{
|
||||
Params: {
|
||||
packId: string;
|
||||
packVersion: string;
|
||||
faceId: string;
|
||||
};
|
||||
}>(
|
||||
"/api/font-packs/:packId/:packVersion/:faceId/web",
|
||||
async (request, reply) => {
|
||||
try {
|
||||
const asset = await applicationService.getFontPackAsset(
|
||||
request.params.packId,
|
||||
request.params.packVersion,
|
||||
request.params.faceId,
|
||||
"web"
|
||||
);
|
||||
if (!asset) {
|
||||
return reply.code(404).send({
|
||||
error: "FONT_PACK_ASSET_NOT_FOUND",
|
||||
message: "未找到指定字体包资源"
|
||||
});
|
||||
}
|
||||
return reply
|
||||
.header("content-type", asset.contentType)
|
||||
.header("cache-control", "public, max-age=31536000, immutable")
|
||||
.header("content-security-policy", "default-src 'none'; sandbox")
|
||||
.header("x-content-type-options", "nosniff")
|
||||
.header("etag", `\"${asset.sha256}\"`)
|
||||
.send(asset.content);
|
||||
} catch {
|
||||
return reply.code(404).send({
|
||||
error: "FONT_PACK_ASSET_NOT_FOUND",
|
||||
message: "未找到指定字体包资源"
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
app.post<{ Body: RenderRequestBody }>(
|
||||
"/api/render",
|
||||
async (request, reply) => {
|
||||
|
||||
Reference in New Issue
Block a user