feat: 实现 Web 与 Desktop DOCX 导出交互
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import {
|
||||
ApplicationRequestError,
|
||||
DocxExportServiceError
|
||||
} from "@md-to-pdf/application";
|
||||
import type {
|
||||
DocxCapability,
|
||||
DocxExportDiagnostics,
|
||||
DocxExportErrorCode,
|
||||
DocxGenerationTimings
|
||||
} from "@md-to-pdf/core";
|
||||
import { docxExportErrorCodeSchema } from "@md-to-pdf/core";
|
||||
|
||||
export interface DesktopDocxExportSuccess {
|
||||
ok: true;
|
||||
saved: boolean;
|
||||
fileName: string;
|
||||
diagnostics: DocxExportDiagnostics;
|
||||
timings: DocxGenerationTimings;
|
||||
}
|
||||
|
||||
export interface DesktopDocxExportFailure {
|
||||
ok: false;
|
||||
error: DocxExportErrorCode;
|
||||
message: string;
|
||||
retryable: boolean;
|
||||
}
|
||||
|
||||
export type DesktopDocxExportOutcome =
|
||||
| DesktopDocxExportSuccess
|
||||
| DesktopDocxExportFailure;
|
||||
|
||||
export type DesktopDocxCapability = DocxCapability;
|
||||
|
||||
export function toDesktopDocxExportFailure(
|
||||
error: unknown
|
||||
): DesktopDocxExportFailure {
|
||||
if (error instanceof ApplicationRequestError) {
|
||||
const parsedCode = docxExportErrorCodeSchema.safeParse(
|
||||
error.code
|
||||
);
|
||||
if (!parsedCode.success) {
|
||||
return {
|
||||
ok: false,
|
||||
error: "DOCX_GENERATION_FAILED",
|
||||
message: "DOCX 导出失败",
|
||||
retryable: false
|
||||
};
|
||||
}
|
||||
return {
|
||||
ok: false,
|
||||
error: parsedCode.data,
|
||||
message: error.message,
|
||||
retryable: false
|
||||
};
|
||||
}
|
||||
if (error instanceof DocxExportServiceError) {
|
||||
return {
|
||||
ok: false,
|
||||
error: error.code,
|
||||
message: error.message,
|
||||
retryable: error.retryable
|
||||
};
|
||||
}
|
||||
return {
|
||||
ok: false,
|
||||
error: "DOCX_GENERATION_FAILED",
|
||||
message: "DOCX 导出失败",
|
||||
retryable: false
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user