fix: 内置DOCX双中文字体包
This commit is contained in:
@@ -166,6 +166,7 @@ ENV HOST=127.0.0.1 \
|
||||
FONT_PACK_ROOT=/app/.local/font-packs
|
||||
|
||||
RUN test -f /app/.local/font-packs/mdtp-serif-sc/1.0.0/font-pack.json
|
||||
RUN test -f /app/.local/font-packs/mdtp-sans-sc/1.0.0/font-pack.json
|
||||
|
||||
USER pwuser
|
||||
|
||||
|
||||
@@ -15,12 +15,10 @@ const image = process.env.MD_TO_PDF_IMAGE?.trim() || "md-to-pdf:local";
|
||||
const fontPackRoot = path.resolve(
|
||||
path.join(repositoryRoot, "output", "font-packs", "root")
|
||||
);
|
||||
const manifestPath = path.join(
|
||||
fontPackRoot,
|
||||
"mdtp-serif-sc",
|
||||
"1.0.0",
|
||||
"font-pack.json"
|
||||
);
|
||||
const expectedFontPacks = [
|
||||
{ id: "mdtp-serif-sc", version: "1.0.0" },
|
||||
{ id: "mdtp-sans-sc", version: "1.0.0" }
|
||||
];
|
||||
|
||||
function assert(condition, message) {
|
||||
if (!condition) {
|
||||
@@ -126,7 +124,14 @@ assert(
|
||||
fontPackStatus?.isDirectory(),
|
||||
`未找到有效字体包根目录:${fontPackRoot}。请先运行 npm run build:font-pack。`
|
||||
);
|
||||
const localManifest = await readFile(manifestPath);
|
||||
const localManifests = await Promise.all(
|
||||
expectedFontPacks.map(async (pack) => ({
|
||||
...pack,
|
||||
content: await readFile(
|
||||
path.join(fontPackRoot, pack.id, pack.version, "font-pack.json")
|
||||
)
|
||||
}))
|
||||
);
|
||||
const buildEnvironment = {
|
||||
...process.env,
|
||||
MD_TO_PDF_IMAGE: image
|
||||
@@ -137,22 +142,26 @@ run(
|
||||
{ env: buildEnvironment }
|
||||
);
|
||||
run("docker", ["image", "inspect", image], { capture: true });
|
||||
const embeddedManifestHash = run(
|
||||
"docker",
|
||||
[
|
||||
"run",
|
||||
"--rm",
|
||||
"--entrypoint",
|
||||
"sha256sum",
|
||||
image,
|
||||
"/app/.local/font-packs/mdtp-serif-sc/1.0.0/font-pack.json"
|
||||
],
|
||||
{ capture: true }
|
||||
).split(/\s+/u)[0];
|
||||
assert(
|
||||
embeddedManifestHash === sha256(localManifest),
|
||||
"镜像内字体包清单与本次受校验构建产物不一致"
|
||||
);
|
||||
const embeddedManifestHashes = {};
|
||||
for (const manifest of localManifests) {
|
||||
const embeddedHash = run(
|
||||
"docker",
|
||||
[
|
||||
"run",
|
||||
"--rm",
|
||||
"--entrypoint",
|
||||
"sha256sum",
|
||||
image,
|
||||
`/app/.local/font-packs/${manifest.id}/${manifest.version}/font-pack.json`
|
||||
],
|
||||
{ capture: true }
|
||||
).split(/\s+/u)[0];
|
||||
assert(
|
||||
embeddedHash === sha256(manifest.content),
|
||||
`镜像内字体包清单不一致:${manifest.id}@${manifest.version}`
|
||||
);
|
||||
embeddedManifestHashes[`${manifest.id}@${manifest.version}`] = embeddedHash;
|
||||
}
|
||||
|
||||
const port = await freePort();
|
||||
const projectName = `morphdoc-font-pack-${randomUUID().slice(0, 8)}`;
|
||||
@@ -237,7 +246,7 @@ try {
|
||||
`${JSON.stringify(
|
||||
{
|
||||
image,
|
||||
embeddedManifestSha256: embeddedManifestHash,
|
||||
embeddedManifestSha256: embeddedManifestHashes,
|
||||
runtimeFontPackMount: false,
|
||||
fontPackAvailable: true,
|
||||
pandocVersion: capability.detectedVersion,
|
||||
|
||||
Reference in New Issue
Block a user