test: 建立 DOCX 自动化验收门禁
This commit is contained in:
@@ -52,6 +52,7 @@ import {
|
||||
toDesktopDocxExportFailure,
|
||||
type DesktopDocxExportOutcome
|
||||
} from "./docx-contract.js";
|
||||
import { saveDesktopDocx } from "./desktop-docx-save.js";
|
||||
import { ElectronDocxMediaEngine } from "./electron-docx-media-engine.js";
|
||||
import {
|
||||
parseMarkdownRenderRequest,
|
||||
@@ -987,16 +988,14 @@ export class DesktopApplicationController {
|
||||
timings: generated.timings
|
||||
};
|
||||
}
|
||||
const targetPath = selection.filePath
|
||||
.toLowerCase()
|
||||
.endsWith(".docx")
|
||||
? selection.filePath
|
||||
: `${selection.filePath}.docx`;
|
||||
await writeFile(targetPath, generated.docx);
|
||||
const saved = await saveDesktopDocx(
|
||||
selection.filePath,
|
||||
generated.docx
|
||||
);
|
||||
return {
|
||||
ok: true,
|
||||
saved: true,
|
||||
fileName: path.basename(targetPath),
|
||||
fileName: saved.fileName,
|
||||
diagnostics: generated.diagnostics,
|
||||
timings: generated.timings
|
||||
};
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import path from "node:path";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
|
||||
export function resolveDesktopDocxTargetPath(selectedPath: string) {
|
||||
return selectedPath.toLowerCase().endsWith(".docx")
|
||||
? selectedPath
|
||||
: `${selectedPath}.docx`;
|
||||
}
|
||||
|
||||
export async function saveDesktopDocx(
|
||||
selectedPath: string,
|
||||
content: Uint8Array
|
||||
) {
|
||||
if (!selectedPath || content.byteLength === 0) {
|
||||
throw new Error("DOCX 保存参数无效");
|
||||
}
|
||||
const targetPath = resolveDesktopDocxTargetPath(selectedPath);
|
||||
await writeFile(targetPath, content);
|
||||
return {
|
||||
targetPath,
|
||||
fileName: path.basename(targetPath)
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user