mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 14:53:44 +08:00
1 parent
6e8eb7cfcc
commit
5dea48d54b
7 files changed
+169
-40
No files matched your search
@@ -29,6 +29,7 @@ self.onmessage = ({ data }) => {
|
||||
operations.get(data.id)?.abort();
|
||||
return;
|
||||
}
|
||||
if (data.name === "ofdgoResources") operations.set(data.id, new AbortController());
|
||||
if (data.name === "ofdgoImportImages" || data.name === "ofdgoExportImages" || data.name === "ofdgoConvertFile" || data.name === "ofdgoPackFiles" || data.name === "ofdgoConvertPDF" || data.name === "ofdgoExportPage" || data.name === "ofdgoExportDocument" || data.name === "ofdgoExportAttachment" || data.name === "ofdgoExportResource" || data.name === "ofdgoExportMedia" || data.name === "ofdgoExportVersion" || data.name === "ofdgoSaveDocument" || data.name === "ofdgoSaveSigned" || data.name === "ofdgoImportPages") {
|
||||
operations.set(data.id, new AbortController());
|
||||
}
|
||||
@@ -168,6 +169,7 @@ async function handleMessage({ id, name, args }) {
|
||||
const importing = name === "ofdgoImportPages" || name === "ofdgoImportImages";
|
||||
const converting = name === "ofdgoConvertPDF";
|
||||
const saving = name === "ofdgoSaveDocument" || name === "ofdgoSaveSigned";
|
||||
const resources = name === "ofdgoResources";
|
||||
const key = name === "ofdgoOpen" ? args[3]?.key : name === "ofdgoSaveSigned" || name === "ofdgoLoadImport" ? args[1]?.key : null;
|
||||
const keyPassword = name === "ofdgoOpen" ? args[3]?.keyPassword : name === "ofdgoSaveSigned" || name === "ofdgoLoadImport" ? args[1]?.keyPassword : null;
|
||||
const password = converting ? args[2] : name === "ofdgoSetEncryption" ? args[0]?.password : name === "ofdgoOpen" ? args[3]?.password : name === "ofdgoLoadImport" ? args[1]?.password : null;
|
||||
@@ -210,7 +212,9 @@ async function handleMessage({ id, name, args }) {
|
||||
};
|
||||
channel.port2.postMessage(null);
|
||||
};
|
||||
if (importing || converting) {
|
||||
if (resources) {
|
||||
args.push(done => finish(done));
|
||||
} else if (importing || converting) {
|
||||
args.push((phase, completed, total, done) => {
|
||||
self.postMessage({ id, type: importing ? "import" : "conversion", phase, completed, total });
|
||||
finish(done, null, importing && phase === "commit");
|
||||
@@ -259,7 +263,7 @@ async function handleMessage({ id, name, args }) {
|
||||
const payload = await globalThis[name](...args);
|
||||
signal?.throwIfAborted();
|
||||
const result = typeof payload === "string" ? JSON.parse(payload) : payload;
|
||||
if (signal && !importing && !converting && result.ok) {
|
||||
if (signal && !importing && !converting && !resources && result.ok) {
|
||||
operations.delete(id);
|
||||
result.data.size = size;
|
||||
if (name !== "ofdgoExportMedia") self.postMessage({ id, type: "export", stage: "save" });
|
||||
@@ -278,7 +282,7 @@ async function handleMessage({ id, name, args }) {
|
||||
await output?.abort().catch(() => {});
|
||||
const result = { id, ok: false, error: err.message };
|
||||
if (signal?.aborted) {
|
||||
result.error = importing ? "导入已取消" : converting ? "转换已取消" : "导出已取消";
|
||||
result.error = resources ? "查询已取消" : importing ? "导入已取消" : converting ? "转换已取消" : "导出已取消";
|
||||
result.canceled = true;
|
||||
}
|
||||
self.postMessage(result);
|
||||
|
||||
Reference in new issue
Block a user