@clazic/kordoc 2.6.0 → 2.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-TND4YFBV.js → chunk-4X5JCZFZ.js} +2 -2
- package/dist/{chunk-TS3F57LY.js → chunk-BZPZXI66.js} +349 -66
- package/dist/chunk-BZPZXI66.js.map +1 -0
- package/dist/cli.js +46 -11
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +394 -100
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +63 -7
- package/dist/index.d.ts +63 -7
- package/dist/index.js +380 -86
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +2 -2
- package/dist/{utils-F66K7PXH.js → utils-56QT5C33.js} +2 -2
- package/dist/{watch-2S5ULHAM.js → watch-HRNMJWSE.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-TS3F57LY.js.map +0 -1
- /package/dist/{chunk-TND4YFBV.js.map → chunk-4X5JCZFZ.js.map} +0 -0
- /package/dist/{utils-F66K7PXH.js.map → utils-56QT5C33.js.map} +0 -0
- /package/dist/{watch-2S5ULHAM.js.map → watch-HRNMJWSE.js.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/utils.ts
|
|
4
|
-
var VERSION = true ? "2.
|
|
4
|
+
var VERSION = true ? "2.6.0" : "0.0.0-dev";
|
|
5
5
|
function toArrayBuffer(buf) {
|
|
6
6
|
if (buf.byteOffset === 0 && buf.byteLength === buf.buffer.byteLength) {
|
|
7
7
|
return buf.buffer;
|
|
@@ -105,4 +105,4 @@ export {
|
|
|
105
105
|
classifyError,
|
|
106
106
|
normalizeKordocError
|
|
107
107
|
};
|
|
108
|
-
//# sourceMappingURL=chunk-
|
|
108
|
+
//# sourceMappingURL=chunk-4X5JCZFZ.js.map
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
precheckZipSize,
|
|
8
8
|
sanitizeHref,
|
|
9
9
|
toArrayBuffer
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-4X5JCZFZ.js";
|
|
11
11
|
import {
|
|
12
12
|
parsePageRange
|
|
13
13
|
} from "./chunk-MOL7MDBG.js";
|
|
@@ -9836,19 +9836,206 @@ var ConvertError = class extends Error {
|
|
|
9836
9836
|
}
|
|
9837
9837
|
};
|
|
9838
9838
|
|
|
9839
|
-
// src/convert/
|
|
9840
|
-
|
|
9841
|
-
|
|
9842
|
-
|
|
9839
|
+
// src/convert/installer.ts
|
|
9840
|
+
import { homedir } from "os";
|
|
9841
|
+
import { join as join2, delimiter } from "path";
|
|
9842
|
+
import { mkdir, access, symlink, rm } from "fs/promises";
|
|
9843
|
+
import { createWriteStream } from "fs";
|
|
9844
|
+
import { spawn } from "child_process";
|
|
9845
|
+
var CACHE_DIR = join2(homedir(), ".cache", "kordoc", "libreoffice");
|
|
9846
|
+
var VERSION_FILE = join2(CACHE_DIR, "version");
|
|
9847
|
+
var PACKAGES = {
|
|
9848
|
+
darwin: {
|
|
9849
|
+
url: "https://download.documentfoundation.org/libreoffice/stable/24.8.4/mac/x86_64/LibreOffice_24.8.4_MacOS_x86-64.dmg",
|
|
9850
|
+
binPath: "LibreOffice.app/Contents/MacOS/soffice",
|
|
9851
|
+
sizeMb: 300
|
|
9852
|
+
},
|
|
9853
|
+
linux: {
|
|
9854
|
+
url: "https://download.documentfoundation.org/libreoffice/stable/24.8.4/deb/x86_64/LibreOffice_24.8.4_Linux_x86-64_deb.tar.gz",
|
|
9855
|
+
binPath: "opt/libreoffice24.8/program/soffice",
|
|
9856
|
+
sizeMb: 200
|
|
9857
|
+
},
|
|
9858
|
+
win32: {
|
|
9859
|
+
url: "https://download.documentfoundation.org/libreoffice/stable/24.8.4/win/x86_64/LibreOffice_24.8.4_Win_x86-64.msi",
|
|
9860
|
+
binPath: "LibreOffice/program/soffice.exe",
|
|
9861
|
+
sizeMb: 350
|
|
9862
|
+
}
|
|
9863
|
+
};
|
|
9864
|
+
async function findInPath() {
|
|
9843
9865
|
try {
|
|
9866
|
+
const { runCommand } = await import("./utils-56QT5C33.js");
|
|
9844
9867
|
await runCommand("soffice", ["--version"]);
|
|
9868
|
+
return "soffice";
|
|
9869
|
+
} catch {
|
|
9870
|
+
return null;
|
|
9871
|
+
}
|
|
9872
|
+
}
|
|
9873
|
+
async function findInCache() {
|
|
9874
|
+
const cachedBin = join2(CACHE_DIR, "bin", "soffice");
|
|
9875
|
+
try {
|
|
9876
|
+
await access(cachedBin);
|
|
9877
|
+
return cachedBin;
|
|
9878
|
+
} catch {
|
|
9879
|
+
return null;
|
|
9880
|
+
}
|
|
9881
|
+
}
|
|
9882
|
+
async function downloadWithProgress(url, dest, totalBytes, onProgress) {
|
|
9883
|
+
const response = await fetch(url);
|
|
9884
|
+
if (!response.body) throw new Error("\uB2E4\uC6B4\uB85C\uB4DC \uC2E4\uD328: response body \uC5C6\uC74C");
|
|
9885
|
+
const file = createWriteStream(dest);
|
|
9886
|
+
const reader = response.body.getReader();
|
|
9887
|
+
let downloaded = 0;
|
|
9888
|
+
try {
|
|
9889
|
+
while (true) {
|
|
9890
|
+
const { done, value } = await reader.read();
|
|
9891
|
+
if (done) break;
|
|
9892
|
+
file.write(value);
|
|
9893
|
+
downloaded += value.length;
|
|
9894
|
+
onProgress?.(downloaded, totalBytes);
|
|
9895
|
+
}
|
|
9896
|
+
} finally {
|
|
9897
|
+
file.end();
|
|
9898
|
+
reader.releaseLock();
|
|
9899
|
+
}
|
|
9900
|
+
}
|
|
9901
|
+
async function installForPlatform(pkg, onProgress) {
|
|
9902
|
+
const platform = process.platform;
|
|
9903
|
+
await mkdir(CACHE_DIR, { recursive: true });
|
|
9904
|
+
const downloadPath = join2(CACHE_DIR, `download-${Date.now()}`);
|
|
9905
|
+
await downloadWithProgress(pkg.url, downloadPath, pkg.sizeMb * 1024 * 1024, onProgress);
|
|
9906
|
+
try {
|
|
9907
|
+
if (platform === "darwin") {
|
|
9908
|
+
return await installMacOS(pkg, downloadPath);
|
|
9909
|
+
} else if (platform === "linux") {
|
|
9910
|
+
return await installLinux(pkg, downloadPath);
|
|
9911
|
+
} else if (platform === "win32") {
|
|
9912
|
+
return await installWindows(pkg, downloadPath);
|
|
9913
|
+
}
|
|
9914
|
+
} catch (err) {
|
|
9915
|
+
await rm(downloadPath, { force: true });
|
|
9916
|
+
throw err;
|
|
9917
|
+
}
|
|
9918
|
+
throw new ConvertError("UNSUPPORTED_PLATFORM", `${platform}\uC740 \uC790\uB3D9 \uC124\uCE58\uB97C \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4`);
|
|
9919
|
+
}
|
|
9920
|
+
async function installMacOS(pkg, downloadPath) {
|
|
9921
|
+
const mountPoint = `/Volumes/LibreOffice_${Date.now()}`;
|
|
9922
|
+
await new Promise((resolve2, reject) => {
|
|
9923
|
+
const child = spawn("hdiutil", ["attach", "-nobrowse", "-mountpoint", mountPoint, downloadPath]);
|
|
9924
|
+
child.on("close", (code) => code === 0 ? resolve2() : reject(new Error("dmg \uB9C8\uC6B4\uD2B8 \uC2E4\uD328")));
|
|
9925
|
+
});
|
|
9926
|
+
try {
|
|
9927
|
+
const appSource = join2(mountPoint, "LibreOffice.app");
|
|
9928
|
+
const appDest = join2(CACHE_DIR, "LibreOffice.app");
|
|
9929
|
+
await new Promise((resolve2, reject) => {
|
|
9930
|
+
const child = spawn("cp", ["-R", appSource, appDest]);
|
|
9931
|
+
child.on("close", (code) => code === 0 ? resolve2() : reject(new Error(".app \uBCF5\uC0AC \uC2E4\uD328")));
|
|
9932
|
+
});
|
|
9933
|
+
} finally {
|
|
9934
|
+
await new Promise((resolve2) => {
|
|
9935
|
+
const child = spawn("hdiutil", ["detach", mountPoint]);
|
|
9936
|
+
child.on("close", () => resolve2());
|
|
9937
|
+
});
|
|
9938
|
+
}
|
|
9939
|
+
await rm(downloadPath, { force: true });
|
|
9940
|
+
return await createSymlink(join2(CACHE_DIR, pkg.binPath));
|
|
9941
|
+
}
|
|
9942
|
+
async function installLinux(pkg, downloadPath) {
|
|
9943
|
+
const extractDir = join2(CACHE_DIR, `extract-${Date.now()}`);
|
|
9944
|
+
await mkdir(extractDir, { recursive: true });
|
|
9945
|
+
await new Promise((resolve2, reject) => {
|
|
9946
|
+
const child = spawn("tar", ["xzf", downloadPath, "-C", extractDir]);
|
|
9947
|
+
child.on("close", (code) => code === 0 ? resolve2() : reject(new Error("\uC555\uCD95 \uD574\uC81C \uC2E4\uD328")));
|
|
9948
|
+
});
|
|
9949
|
+
const debsDir = join2(extractDir, "DEBS");
|
|
9950
|
+
try {
|
|
9951
|
+
await access(debsDir);
|
|
9952
|
+
const entries = await (await import("fs/promises")).readdir(debsDir);
|
|
9953
|
+
for (const entry of entries) {
|
|
9954
|
+
if (entry.endsWith(".deb")) {
|
|
9955
|
+
await new Promise((resolve2, reject) => {
|
|
9956
|
+
const child = spawn("dpkg-deb", ["-x", join2(debsDir, entry), CACHE_DIR]);
|
|
9957
|
+
child.on("close", (code) => code === 0 ? resolve2() : reject(new Error(`${entry} \uCD94\uCD9C \uC2E4\uD328`)));
|
|
9958
|
+
});
|
|
9959
|
+
}
|
|
9960
|
+
}
|
|
9961
|
+
} catch {
|
|
9962
|
+
}
|
|
9963
|
+
await rm(downloadPath, { force: true });
|
|
9964
|
+
await rm(extractDir, { recursive: true, force: true });
|
|
9965
|
+
return await createSymlink(join2(CACHE_DIR, pkg.binPath));
|
|
9966
|
+
}
|
|
9967
|
+
async function installWindows(pkg, downloadPath) {
|
|
9968
|
+
await new Promise((resolve2, reject) => {
|
|
9969
|
+
const child = spawn("msiexec", ["/a", downloadPath, "/qn", `TARGETDIR=${CACHE_DIR}`]);
|
|
9970
|
+
child.on("close", (code) => code === 0 ? resolve2() : reject(new Error("MSI \uC124\uCE58 \uC2E4\uD328")));
|
|
9971
|
+
});
|
|
9972
|
+
await rm(downloadPath, { force: true });
|
|
9973
|
+
return join2(CACHE_DIR, pkg.binPath);
|
|
9974
|
+
}
|
|
9975
|
+
async function createSymlink(actualBin) {
|
|
9976
|
+
const binDir = join2(CACHE_DIR, "bin");
|
|
9977
|
+
await mkdir(binDir, { recursive: true });
|
|
9978
|
+
const linkBin = join2(binDir, "soffice");
|
|
9979
|
+
try {
|
|
9980
|
+
await symlink(actualBin, linkBin);
|
|
9845
9981
|
} catch {
|
|
9982
|
+
}
|
|
9983
|
+
process.env.PATH = `${binDir}${delimiter}${process.env.PATH}`;
|
|
9984
|
+
return linkBin;
|
|
9985
|
+
}
|
|
9986
|
+
async function installLibreOffice(onProgress) {
|
|
9987
|
+
const platform = process.platform;
|
|
9988
|
+
const pkg = PACKAGES[platform];
|
|
9989
|
+
if (!pkg) {
|
|
9846
9990
|
throw new ConvertError(
|
|
9991
|
+
"UNSUPPORTED_PLATFORM",
|
|
9992
|
+
`${platform}\uC740 \uC790\uB3D9 \uC124\uCE58\uB97C \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4. \uC218\uB3D9\uC73C\uB85C LibreOffice\uB97C \uC124\uCE58\uD574 \uC8FC\uC138\uC694.`
|
|
9993
|
+
);
|
|
9994
|
+
}
|
|
9995
|
+
return await installForPlatform(pkg, onProgress);
|
|
9996
|
+
}
|
|
9997
|
+
async function resolveSoffice(emitter, autoInstall = true) {
|
|
9998
|
+
emitter.validate("soffice_check", "LibreOffice \uAC00\uC6A9\uC131 \uD655\uC778 \uC911...");
|
|
9999
|
+
const inPath = await findInPath();
|
|
10000
|
+
if (inPath) {
|
|
10001
|
+
emitter.validate("soffice_found", "\uC2DC\uC2A4\uD15C PATH\uC5D0\uC11C LibreOffice \uBC1C\uACAC", { sofficePath: inPath });
|
|
10002
|
+
return inPath;
|
|
10003
|
+
}
|
|
10004
|
+
const inCache = await findInCache();
|
|
10005
|
+
if (inCache) {
|
|
10006
|
+
emitter.validate("soffice_found", "\uCE90\uC2DC\uB41C LibreOffice \uBC1C\uACAC", { sofficePath: inCache });
|
|
10007
|
+
return inCache;
|
|
10008
|
+
}
|
|
10009
|
+
if (!autoInstall) {
|
|
10010
|
+
emitter.error(
|
|
10011
|
+
"validate",
|
|
9847
10012
|
"SOFFICE_NOT_FOUND",
|
|
9848
|
-
"
|
|
10013
|
+
"LibreOffice\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4",
|
|
10014
|
+
"\uC218\uB3D9\uC73C\uB85C \uC124\uCE58\uD558\uAC70\uB098 autoInstallLibreOffice: true \uC635\uC158\uC744 \uC0AC\uC6A9\uD558\uC138\uC694."
|
|
9849
10015
|
);
|
|
10016
|
+
throw new ConvertError("SOFFICE_NOT_FOUND", "LibreOffice\uAC00 \uC124\uCE58\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4");
|
|
10017
|
+
}
|
|
10018
|
+
emitter.install("install_start", "LibreOffice \uC790\uB3D9 \uC124\uCE58\uB97C \uC2DC\uC791\uD569\uB2C8\uB2E4...");
|
|
10019
|
+
try {
|
|
10020
|
+
const installed = await installLibreOffice((downloaded, total) => {
|
|
10021
|
+
const percent = Math.round(downloaded / total * 100);
|
|
10022
|
+
emitter.install("download_progress", `\uB2E4\uC6B4\uB85C\uB4DC \uC911... ${percent}%`, {
|
|
10023
|
+
percent,
|
|
10024
|
+
downloadedBytes: downloaded,
|
|
10025
|
+
totalBytes: total
|
|
10026
|
+
});
|
|
10027
|
+
});
|
|
10028
|
+
emitter.install("install_complete", "\uC124\uCE58 \uC644\uB8CC", { installedPath: installed });
|
|
10029
|
+
return installed;
|
|
10030
|
+
} catch (err) {
|
|
10031
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
10032
|
+
emitter.install("install_failed", "\uC124\uCE58 \uC2E4\uD328", { error: errorMsg });
|
|
10033
|
+
throw err;
|
|
9850
10034
|
}
|
|
9851
10035
|
}
|
|
10036
|
+
|
|
10037
|
+
// src/convert/libreoffice.ts
|
|
10038
|
+
var libreConvert = libre.convert;
|
|
9852
10039
|
async function convertBuffer(buffer, targetExt, timeoutMs = 6e4) {
|
|
9853
10040
|
return new Promise((resolve2, reject) => {
|
|
9854
10041
|
const timer = setTimeout(() => {
|
|
@@ -9872,6 +10059,54 @@ async function convertBuffer(buffer, targetExt, timeoutMs = 6e4) {
|
|
|
9872
10059
|
});
|
|
9873
10060
|
}
|
|
9874
10061
|
|
|
10062
|
+
// src/convert/events.ts
|
|
10063
|
+
var ConvertEventEmitter = class {
|
|
10064
|
+
listener = null;
|
|
10065
|
+
/** 이벤트 리스너 등록 */
|
|
10066
|
+
setListener(listener) {
|
|
10067
|
+
this.listener = listener;
|
|
10068
|
+
}
|
|
10069
|
+
/** 이벤트 발송 */
|
|
10070
|
+
emit(event) {
|
|
10071
|
+
try {
|
|
10072
|
+
this.listener?.(event);
|
|
10073
|
+
} catch {
|
|
10074
|
+
}
|
|
10075
|
+
}
|
|
10076
|
+
/** 타입 안전한 헬퍼: detect 이벤트 */
|
|
10077
|
+
detect(stage, message, meta) {
|
|
10078
|
+
this.emit({ type: "detect", stage, message, ...meta });
|
|
10079
|
+
}
|
|
10080
|
+
/** 타입 안전한 헬퍼: validate 이벤트 */
|
|
10081
|
+
validate(stage, message, meta) {
|
|
10082
|
+
this.emit({ type: "validate", stage, message, ...meta });
|
|
10083
|
+
}
|
|
10084
|
+
/** 타입 안전한 헬퍼: install 이벤트 */
|
|
10085
|
+
install(stage, message, meta) {
|
|
10086
|
+
this.emit({ type: "install", stage, message, ...meta });
|
|
10087
|
+
}
|
|
10088
|
+
/** 타입 안전한 헬퍼: convert 진행 이벤트 */
|
|
10089
|
+
progress(percent, message) {
|
|
10090
|
+
this.emit({ type: "convert", stage: "convert_progress", message, percent });
|
|
10091
|
+
}
|
|
10092
|
+
/** 타입 안전한 헬퍼: convert 시작 */
|
|
10093
|
+
convertStart(message) {
|
|
10094
|
+
this.emit({ type: "convert", stage: "convert_start", message, percent: 0 });
|
|
10095
|
+
}
|
|
10096
|
+
/** 타입 안전한 헬퍼: convert 완료 */
|
|
10097
|
+
convertDone(message) {
|
|
10098
|
+
this.emit({ type: "convert", stage: "convert_done", message, percent: 100 });
|
|
10099
|
+
}
|
|
10100
|
+
/** 타입 안전한 헬퍼: 완료 이벤트 */
|
|
10101
|
+
complete(result) {
|
|
10102
|
+
this.emit({ type: "complete", stage: "success", message: "\uBCC0\uD658 \uC644\uB8CC", result });
|
|
10103
|
+
}
|
|
10104
|
+
/** 타입 안전한 헬퍼: 에러 이벤트 */
|
|
10105
|
+
error(stage, code, message, suggestion) {
|
|
10106
|
+
this.emit({ type: "error", stage, code, message, recoverable: true, suggestion });
|
|
10107
|
+
}
|
|
10108
|
+
};
|
|
10109
|
+
|
|
9875
10110
|
// src/convert/index.ts
|
|
9876
10111
|
var isConverting = false;
|
|
9877
10112
|
var queue = [];
|
|
@@ -9896,81 +10131,129 @@ async function acquireConvertLock() {
|
|
|
9896
10131
|
});
|
|
9897
10132
|
}
|
|
9898
10133
|
async function convertToPdf(input, options) {
|
|
9899
|
-
|
|
9900
|
-
|
|
9901
|
-
|
|
9902
|
-
buffer = await readFile(input);
|
|
9903
|
-
} else if (Buffer.isBuffer(input)) {
|
|
9904
|
-
buffer = input;
|
|
9905
|
-
} else {
|
|
9906
|
-
buffer = Buffer.from(input);
|
|
9907
|
-
}
|
|
9908
|
-
} catch (err) {
|
|
9909
|
-
return {
|
|
9910
|
-
success: false,
|
|
9911
|
-
code: "PARSE_ERROR",
|
|
9912
|
-
error: `\uC785\uB825 \uC77D\uAE30 \uC2E4\uD328: ${err instanceof Error ? err.message : String(err)}`,
|
|
9913
|
-
stage: "detect"
|
|
9914
|
-
};
|
|
9915
|
-
}
|
|
9916
|
-
const MAX_FILE_SIZE = 500 * 1024 * 1024;
|
|
9917
|
-
if (buffer.length > MAX_FILE_SIZE) {
|
|
9918
|
-
return {
|
|
9919
|
-
success: false,
|
|
9920
|
-
code: "FILE_TOO_LARGE",
|
|
9921
|
-
error: `\uD30C\uC77C \uD06C\uAE30 \uCD08\uACFC: ${(buffer.length / 1024 / 1024).toFixed(1)}MB (\uCD5C\uB300 500MB)`,
|
|
9922
|
-
stage: "detect"
|
|
9923
|
-
};
|
|
10134
|
+
const emitter = new ConvertEventEmitter();
|
|
10135
|
+
if (options?.onEvent) {
|
|
10136
|
+
emitter.setListener(options.onEvent);
|
|
9924
10137
|
}
|
|
9925
|
-
|
|
9926
|
-
|
|
9927
|
-
|
|
9928
|
-
|
|
9929
|
-
|
|
9930
|
-
|
|
9931
|
-
|
|
9932
|
-
};
|
|
10138
|
+
if (options?.onProgress) {
|
|
10139
|
+
const legacyProgress = options.onProgress;
|
|
10140
|
+
emitter.setListener((event) => {
|
|
10141
|
+
if (event.type === "convert" && event.stage === "convert_progress") {
|
|
10142
|
+
legacyProgress(event.percent, event.message);
|
|
10143
|
+
}
|
|
10144
|
+
});
|
|
9933
10145
|
}
|
|
9934
10146
|
try {
|
|
9935
|
-
|
|
9936
|
-
|
|
9937
|
-
|
|
10147
|
+
emitter.detect("reading", "\uC785\uB825 \uD30C\uC77C \uC77D\uB294 \uC911...");
|
|
10148
|
+
let buffer;
|
|
10149
|
+
try {
|
|
10150
|
+
if (typeof input === "string") {
|
|
10151
|
+
buffer = await readFile(input);
|
|
10152
|
+
} else if (Buffer.isBuffer(input)) {
|
|
10153
|
+
buffer = input;
|
|
10154
|
+
} else {
|
|
10155
|
+
buffer = Buffer.from(input);
|
|
10156
|
+
}
|
|
10157
|
+
} catch (err) {
|
|
10158
|
+
emitter.error(
|
|
10159
|
+
"detect",
|
|
10160
|
+
"PARSE_ERROR",
|
|
10161
|
+
`\uC785\uB825 \uC77D\uAE30 \uC2E4\uD328: ${err instanceof Error ? err.message : String(err)}`
|
|
10162
|
+
);
|
|
9938
10163
|
return {
|
|
9939
10164
|
success: false,
|
|
9940
|
-
code:
|
|
9941
|
-
error: err.message
|
|
9942
|
-
stage: "
|
|
10165
|
+
code: "PARSE_ERROR",
|
|
10166
|
+
error: `\uC785\uB825 \uC77D\uAE30 \uC2E4\uD328: ${err instanceof Error ? err.message : String(err)}`,
|
|
10167
|
+
stage: "detect"
|
|
9943
10168
|
};
|
|
9944
10169
|
}
|
|
9945
|
-
|
|
9946
|
-
|
|
9947
|
-
|
|
9948
|
-
|
|
9949
|
-
|
|
9950
|
-
|
|
9951
|
-
|
|
9952
|
-
|
|
9953
|
-
|
|
9954
|
-
|
|
9955
|
-
|
|
9956
|
-
|
|
9957
|
-
|
|
9958
|
-
|
|
10170
|
+
const MAX_FILE_SIZE = 500 * 1024 * 1024;
|
|
10171
|
+
if (buffer.length > MAX_FILE_SIZE) {
|
|
10172
|
+
emitter.error(
|
|
10173
|
+
"detect",
|
|
10174
|
+
"FILE_TOO_LARGE",
|
|
10175
|
+
`\uD30C\uC77C \uD06C\uAE30 \uCD08\uACFC: ${(buffer.length / 1024 / 1024).toFixed(1)}MB (\uCD5C\uB300 500MB)`
|
|
10176
|
+
);
|
|
10177
|
+
return {
|
|
10178
|
+
success: false,
|
|
10179
|
+
code: "FILE_TOO_LARGE",
|
|
10180
|
+
error: `\uD30C\uC77C \uD06C\uAE30 \uCD08\uACFC: ${(buffer.length / 1024 / 1024).toFixed(1)}MB (\uCD5C\uB300 500MB)`,
|
|
10181
|
+
stage: "detect"
|
|
10182
|
+
};
|
|
10183
|
+
}
|
|
10184
|
+
const format = detectFormat(toArrayBuffer(buffer));
|
|
10185
|
+
emitter.detect("format_detected", `\uD3EC\uB9F7 \uAC10\uC9C0 \uC644\uB8CC: ${format}`, { format });
|
|
10186
|
+
if (format !== "hwp" && format !== "hwpx") {
|
|
10187
|
+
emitter.error("detect", "UNSUPPORTED_FORMAT", `\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uD3EC\uB9F7\uC785\uB2C8\uB2E4: ${format}`);
|
|
10188
|
+
return {
|
|
10189
|
+
success: false,
|
|
10190
|
+
code: "UNSUPPORTED_FORMAT",
|
|
10191
|
+
error: `\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uD3EC\uB9F7\uC785\uB2C8\uB2E4: ${format}`,
|
|
10192
|
+
stage: "detect"
|
|
10193
|
+
};
|
|
10194
|
+
}
|
|
10195
|
+
emitter.validate("soffice_check", "LibreOffice \uAC00\uC6A9\uC131 \uD655\uC778 \uC911...");
|
|
10196
|
+
let sofficePath;
|
|
10197
|
+
try {
|
|
10198
|
+
sofficePath = await resolveSoffice(emitter, options?.autoInstallLibreOffice ?? true);
|
|
10199
|
+
} catch (err) {
|
|
10200
|
+
if (err instanceof ConvertError) {
|
|
10201
|
+
return {
|
|
10202
|
+
success: false,
|
|
10203
|
+
code: err.code,
|
|
10204
|
+
error: err.message,
|
|
10205
|
+
stage: "validate"
|
|
10206
|
+
};
|
|
10207
|
+
}
|
|
10208
|
+
throw err;
|
|
10209
|
+
}
|
|
10210
|
+
const releaseLock = await acquireConvertLock();
|
|
10211
|
+
try {
|
|
10212
|
+
emitter.convertStart("\uBCC0\uD658 \uC2DC\uC791...");
|
|
10213
|
+
emitter.progress(10, "\uBCC0\uD658 \uC911...");
|
|
10214
|
+
const pdf = await convertBuffer(buffer, ".pdf", options?.timeoutMs);
|
|
10215
|
+
emitter.progress(100, "\uBCC0\uD658 \uC644\uB8CC");
|
|
10216
|
+
emitter.convertDone("\uBCC0\uD658 \uC644\uB8CC");
|
|
10217
|
+
const result = {
|
|
10218
|
+
success: true,
|
|
10219
|
+
pdf: new Uint8Array(pdf),
|
|
10220
|
+
sourceFormat: format
|
|
10221
|
+
};
|
|
10222
|
+
emitter.complete({
|
|
10223
|
+
sourceFormat: format,
|
|
10224
|
+
pdfSize: pdf.length
|
|
10225
|
+
});
|
|
10226
|
+
return result;
|
|
10227
|
+
} catch (err) {
|
|
10228
|
+
if (err instanceof ConvertError) {
|
|
10229
|
+
emitter.error("convert", err.code, err.message);
|
|
10230
|
+
return {
|
|
10231
|
+
success: false,
|
|
10232
|
+
code: err.code,
|
|
10233
|
+
error: err.message,
|
|
10234
|
+
stage: "convert"
|
|
10235
|
+
};
|
|
10236
|
+
}
|
|
10237
|
+
const errorMsg = err instanceof Error ? err.message : "\uBCC0\uD658 \uC2E4\uD328";
|
|
10238
|
+
emitter.error("convert", classifyError(err), errorMsg);
|
|
9959
10239
|
return {
|
|
9960
10240
|
success: false,
|
|
9961
|
-
code: err
|
|
9962
|
-
error:
|
|
10241
|
+
code: classifyError(err),
|
|
10242
|
+
error: errorMsg,
|
|
9963
10243
|
stage: "convert"
|
|
9964
10244
|
};
|
|
10245
|
+
} finally {
|
|
10246
|
+
releaseLock();
|
|
9965
10247
|
}
|
|
10248
|
+
} catch (unexpectedErr) {
|
|
10249
|
+
const errorMsg = unexpectedErr instanceof Error ? unexpectedErr.message : "\uC608\uC0C1\uCE58 \uBABB\uD55C \uC624\uB958";
|
|
10250
|
+
emitter.error("convert", "PARSE_ERROR", errorMsg);
|
|
9966
10251
|
return {
|
|
9967
10252
|
success: false,
|
|
9968
|
-
code:
|
|
9969
|
-
error:
|
|
10253
|
+
code: "PARSE_ERROR",
|
|
10254
|
+
error: errorMsg,
|
|
9970
10255
|
stage: "convert"
|
|
9971
10256
|
};
|
|
9972
|
-
} finally {
|
|
9973
|
-
releaseLock();
|
|
9974
10257
|
}
|
|
9975
10258
|
}
|
|
9976
10259
|
|
|
@@ -10358,4 +10641,4 @@ export {
|
|
|
10358
10641
|
cfb/cfb.js:
|
|
10359
10642
|
(*! crc32.js (C) 2014-present SheetJS -- http://sheetjs.com *)
|
|
10360
10643
|
*/
|
|
10361
|
-
//# sourceMappingURL=chunk-
|
|
10644
|
+
//# sourceMappingURL=chunk-BZPZXI66.js.map
|