@file-viewer/core 2.0.9 → 2.0.11
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/renderers/wordDocx.js +14 -0
- package/package.json +3 -3
|
@@ -12,6 +12,7 @@ const DOCX_MIN_SCALE = 0.24;
|
|
|
12
12
|
const DOCX_MAX_SCALE = 3;
|
|
13
13
|
const DOCX_ZOOM_STEP = 0.15;
|
|
14
14
|
const DOCX_EMU_PER_CSS_PIXEL = 9525;
|
|
15
|
+
const ZIP_SIGNATURE_PK = 0x504b;
|
|
15
16
|
const loadLibrary = (() => {
|
|
16
17
|
const loader = {
|
|
17
18
|
module: null,
|
|
@@ -26,6 +27,18 @@ const loadLibrary = (() => {
|
|
|
26
27
|
return await loader.load();
|
|
27
28
|
};
|
|
28
29
|
})();
|
|
30
|
+
/**
|
|
31
|
+
* DOCX / DOCM / DOTX / DOTM are OOXML packages, so a valid file must start
|
|
32
|
+
* with a ZIP signature. This catches common enterprise download failures where
|
|
33
|
+
* an object-storage XML error page is saved with a `.docx` extension.
|
|
34
|
+
*/
|
|
35
|
+
const assertValidDocxPackage = (buffer) => {
|
|
36
|
+
const signature = buffer.byteLength >= 4 ? new DataView(buffer).getUint16(0, false) : 0;
|
|
37
|
+
if (signature === ZIP_SIGNATURE_PK) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
throw new Error('文件不是有效的 DOCX/OOXML 压缩包,可能下载不完整或被服务端错误内容替换,请重新上传或检查文件源。');
|
|
41
|
+
};
|
|
29
42
|
const createDocxOptions = (target, context, notifyProgressiveRender) => {
|
|
30
43
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
31
44
|
const docxOptions = (_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.docx;
|
|
@@ -928,6 +941,7 @@ function prepareDocxCloneForExport(target) {
|
|
|
928
941
|
*/
|
|
929
942
|
export default async function (buffer, target, context) {
|
|
930
943
|
var _a;
|
|
944
|
+
assertValidDocxPackage(buffer);
|
|
931
945
|
let hasNotifiedProgressiveRender = false;
|
|
932
946
|
const notifyProgressiveRender = () => {
|
|
933
947
|
var _a;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.11",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Framework-neutral TypeScript core for Flyfish File Viewer",
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@excalidraw/excalidraw": "^0.18.1",
|
|
62
|
-
"@file-viewer/docx": "^0.3.
|
|
63
|
-
"@file-viewer/pptx": "^2.0.
|
|
62
|
+
"@file-viewer/docx": "^0.3.12",
|
|
63
|
+
"@file-viewer/pptx": "^2.0.11",
|
|
64
64
|
"@flyfish-dev/cad-viewer": "^0.6.4",
|
|
65
65
|
"@kenjiuno/msgreader": "^1.28.0",
|
|
66
66
|
"@myriaddreamin/typst-ts-renderer": "0.7.0",
|