template-replacement 3.3.2 → 3.3.3
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/{base-BuKBOMgk.js → base-CJv023nf.js} +127 -112
- package/dist/main/general.js +838 -816
- package/dist/main/sign.js +731 -707
- package/dist/replace/general.js +72 -67
- package/dist/replace/sign.js +134 -127
- package/fileSystem/db/index.ts +1 -1
- package/fileSystem/db/indexedDBCache.ts +67 -51
- package/helper/index.ts +29 -12
- package/index.ts +4 -12
- package/office/zip.ts +3 -3
- package/package.json +8 -8
- package/replace/base.ts +30 -22
- package/replace/general.ts +9 -4
- package/replace/image.ts +6 -2
- package/replace/paramsData.ts +1 -1
- package/replace/sign.ts +19 -10
- package/task/urlDownloadTask.ts +10 -17
- package/temp/index.ts +7 -14
- package/worker/index.ts +4 -2
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
class
|
|
2
|
-
//表配置
|
|
1
|
+
class f {
|
|
3
2
|
// 构造函数
|
|
4
3
|
constructor() {
|
|
5
|
-
this._initFinishCallBackFuns = [], this._isInitFinish = !1, this._dbName = "
|
|
4
|
+
this._initFinishCallBackFuns = [], this._isInitFinish = !1, this._dbName = "template_replacement_db", this._dbversion = 1, this._cacheTableName = "template_files", this._tableMap = {}, this.initDB();
|
|
6
5
|
}
|
|
7
6
|
initDB() {
|
|
8
|
-
return new Promise((e, a) => {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
if (this._db =
|
|
7
|
+
return this._init ? this._init : (this._init = new Promise((e, a) => {
|
|
8
|
+
const i = indexedDB.open(this._dbName, this._dbversion);
|
|
9
|
+
i.onsuccess = (t) => {
|
|
10
|
+
if (this._db = i.result, this._isInitFinish = !0, this._initFinishCallBackFuns) {
|
|
12
11
|
try {
|
|
13
|
-
for (const
|
|
14
|
-
|
|
12
|
+
for (const s of this._initFinishCallBackFuns)
|
|
13
|
+
s();
|
|
15
14
|
} catch {
|
|
16
15
|
}
|
|
17
16
|
this._initFinishCallBackFuns = void 0;
|
|
18
17
|
}
|
|
19
18
|
e(t);
|
|
20
|
-
},
|
|
19
|
+
}, i.onerror = (t) => {
|
|
21
20
|
console.error(t), a(t);
|
|
22
|
-
},
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
keyPath: "
|
|
21
|
+
}, i.onupgradeneeded = (t) => {
|
|
22
|
+
let s = i.result;
|
|
23
|
+
s.objectStoreNames.contains(this._cacheTableName) || s.createObjectStore(this._cacheTableName, {
|
|
24
|
+
keyPath: "key"
|
|
26
25
|
// 设置主键
|
|
27
26
|
}), e(t);
|
|
28
27
|
};
|
|
29
|
-
});
|
|
28
|
+
}), this._init);
|
|
30
29
|
}
|
|
31
30
|
async awaitInit() {
|
|
32
31
|
this._isInitFinish || !this._initFinishCallBackFuns || await new Promise((e, a) => {
|
|
@@ -41,56 +40,64 @@ class m {
|
|
|
41
40
|
}
|
|
42
41
|
/**
|
|
43
42
|
* @description : 更新数据
|
|
44
|
-
* @param {
|
|
43
|
+
* @param {templateData} params 添加到数据库中的数据 { key: 文件key, data: 文件blob }
|
|
45
44
|
* @return {*}
|
|
46
45
|
*/
|
|
47
46
|
putData(e) {
|
|
48
|
-
return new Promise(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
s(
|
|
54
|
-
|
|
47
|
+
return new Promise((a, i) => {
|
|
48
|
+
this.store("readwrite").then((t) => {
|
|
49
|
+
const s = t.put(e);
|
|
50
|
+
s.onsuccess = (n) => {
|
|
51
|
+
a(n);
|
|
52
|
+
}, s.onerror = (n) => {
|
|
53
|
+
i(n);
|
|
54
|
+
};
|
|
55
|
+
}).catch(i);
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
58
|
// 通过主键读取数据
|
|
58
59
|
getDataByKey(e) {
|
|
59
|
-
return new Promise(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
s(
|
|
65
|
-
|
|
60
|
+
return new Promise((a, i) => {
|
|
61
|
+
this.store().then((t) => {
|
|
62
|
+
const s = t.get(e);
|
|
63
|
+
s.onsuccess = () => {
|
|
64
|
+
a(s.result);
|
|
65
|
+
}, s.onerror = (n) => {
|
|
66
|
+
i(n);
|
|
67
|
+
};
|
|
68
|
+
}).catch(i);
|
|
66
69
|
});
|
|
67
70
|
}
|
|
68
71
|
// 通过主键移除数据
|
|
69
72
|
deleteDataByKey(e) {
|
|
70
|
-
return new Promise(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
s(
|
|
76
|
-
|
|
73
|
+
return new Promise((a, i) => {
|
|
74
|
+
this.store().then((t) => {
|
|
75
|
+
const s = t.delete(e);
|
|
76
|
+
s.onsuccess = () => {
|
|
77
|
+
a(s.result);
|
|
78
|
+
}, s.onerror = (n) => {
|
|
79
|
+
i(n);
|
|
80
|
+
};
|
|
81
|
+
}).catch(i);
|
|
77
82
|
});
|
|
78
83
|
}
|
|
79
84
|
// 清空数据库数据
|
|
80
85
|
clearDB() {
|
|
81
|
-
return new Promise(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
return new Promise((e, a) => {
|
|
87
|
+
this.store("readwrite").then((i) => {
|
|
88
|
+
const t = i.clear();
|
|
89
|
+
t.onsuccess = (s) => {
|
|
90
|
+
e(s);
|
|
91
|
+
}, t.onerror = (s) => {
|
|
92
|
+
a(s);
|
|
93
|
+
};
|
|
94
|
+
}).catch(a);
|
|
88
95
|
});
|
|
89
96
|
}
|
|
90
97
|
}
|
|
91
|
-
new
|
|
92
|
-
var l = /* @__PURE__ */ ((
|
|
93
|
-
class
|
|
98
|
+
new f();
|
|
99
|
+
var l = /* @__PURE__ */ ((c) => (c.word = "word", c.excel = "excel", c.unknown = "unknown", c))(l || {});
|
|
100
|
+
class m {
|
|
94
101
|
#e = [];
|
|
95
102
|
#t;
|
|
96
103
|
constructor(e) {
|
|
@@ -104,37 +111,45 @@ class f {
|
|
|
104
111
|
}
|
|
105
112
|
async extractVariables(e) {
|
|
106
113
|
e || (e = this.#e);
|
|
107
|
-
const a = {},
|
|
114
|
+
const a = {}, i = [];
|
|
108
115
|
for (const t of e)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
116
|
+
i.push(new Promise(async (s) => {
|
|
117
|
+
try {
|
|
118
|
+
const n = await t.getBuffer();
|
|
119
|
+
n && (t.isDecode || await t.type() !== l.unknown) && (a[t.name] = await this.#t.extract_one_file_variable_names(n, t.isDecode)), s();
|
|
120
|
+
} catch (n) {
|
|
121
|
+
console.error(n);
|
|
122
|
+
}
|
|
112
123
|
}));
|
|
113
|
-
return await Promise.all(
|
|
124
|
+
return await Promise.all(i), a;
|
|
114
125
|
}
|
|
115
126
|
async extractMedias(e) {
|
|
116
127
|
e || (e = this.#e);
|
|
117
|
-
const a = {},
|
|
128
|
+
const a = {}, i = [];
|
|
118
129
|
for (const t of e)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
id
|
|
127
|
-
|
|
128
|
-
|
|
130
|
+
i.push(new Promise(async (s) => {
|
|
131
|
+
try {
|
|
132
|
+
const n = await t.getBuffer();
|
|
133
|
+
if (n && (t.isDecode || await t.type() !== l.unknown)) {
|
|
134
|
+
let r = await this.#t.extract_one_file_medias(n, t.isDecode);
|
|
135
|
+
if (a[t.name] = [], r && Array.isArray(r))
|
|
136
|
+
for (const o of r)
|
|
137
|
+
o.id && o.data && a[t.name].push({
|
|
138
|
+
id: o.id,
|
|
139
|
+
data: new Uint8Array(o.data)
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
s();
|
|
143
|
+
} catch (n) {
|
|
144
|
+
console.error(n);
|
|
129
145
|
}
|
|
130
|
-
i();
|
|
131
146
|
}));
|
|
132
|
-
return await Promise.all(
|
|
147
|
+
return await Promise.all(i), a;
|
|
133
148
|
}
|
|
134
|
-
async handle(e, a,
|
|
149
|
+
async handle(e, a, i = !1) {
|
|
135
150
|
return [];
|
|
136
151
|
}
|
|
137
|
-
async handleMultipleParams(e, a,
|
|
152
|
+
async handleMultipleParams(e, a, i = !1) {
|
|
138
153
|
return [];
|
|
139
154
|
}
|
|
140
155
|
async sign(e) {
|
|
@@ -142,10 +157,10 @@ class f {
|
|
|
142
157
|
}
|
|
143
158
|
async execute(e, a) {
|
|
144
159
|
a || (a = this.#e);
|
|
145
|
-
const
|
|
146
|
-
for (const
|
|
147
|
-
|
|
148
|
-
await Promise.all(
|
|
160
|
+
const i = [];
|
|
161
|
+
for (const n of a)
|
|
162
|
+
i.push(n.getBuffer());
|
|
163
|
+
await Promise.all(i);
|
|
149
164
|
const t = {
|
|
150
165
|
//需要解密的文件
|
|
151
166
|
decode: {
|
|
@@ -158,34 +173,34 @@ class f {
|
|
|
158
173
|
uint8Arrays: []
|
|
159
174
|
}
|
|
160
175
|
};
|
|
161
|
-
for (const
|
|
162
|
-
|
|
163
|
-
const
|
|
176
|
+
for (const n of a)
|
|
177
|
+
n.uint8Array && (n.isDecode ? (t.decode.names.push(n.name), t.decode.uint8Arrays.push(n.uint8Array)) : (t.noDecode.names.push(n.name), t.noDecode.uint8Arrays.push(n.uint8Array)));
|
|
178
|
+
const s = await Promise.all([
|
|
164
179
|
this._execute(e, t.noDecode.names, t.noDecode.uint8Arrays, !1),
|
|
165
180
|
this._execute(e, t.decode.names, t.decode.uint8Arrays, !0)
|
|
166
181
|
]);
|
|
167
182
|
return {
|
|
168
|
-
...
|
|
169
|
-
...
|
|
183
|
+
...s[0],
|
|
184
|
+
...s[1]
|
|
170
185
|
};
|
|
171
186
|
}
|
|
172
|
-
async _execute(e, a,
|
|
173
|
-
const
|
|
174
|
-
if (!
|
|
175
|
-
return
|
|
176
|
-
const
|
|
177
|
-
for (let
|
|
178
|
-
const
|
|
179
|
-
|
|
187
|
+
async _execute(e, a, i, t = !1) {
|
|
188
|
+
const s = {};
|
|
189
|
+
if (!i.length)
|
|
190
|
+
return s;
|
|
191
|
+
const n = await this.handle(e, i, t);
|
|
192
|
+
for (let r = 0; r < n.length; r++) {
|
|
193
|
+
const o = n[r];
|
|
194
|
+
o.length && (s[a[r]] = o);
|
|
180
195
|
}
|
|
181
|
-
return
|
|
196
|
+
return s;
|
|
182
197
|
}
|
|
183
198
|
async executeMultipleParams(e, a) {
|
|
184
199
|
a || (a = this.#e);
|
|
185
|
-
const
|
|
186
|
-
for (const
|
|
187
|
-
|
|
188
|
-
await Promise.all(
|
|
200
|
+
const i = [];
|
|
201
|
+
for (const r of a)
|
|
202
|
+
i.push(r.getBuffer());
|
|
203
|
+
await Promise.all(i);
|
|
189
204
|
const t = {
|
|
190
205
|
//需要解密的文件
|
|
191
206
|
decode: {
|
|
@@ -198,37 +213,37 @@ class f {
|
|
|
198
213
|
uint8Arrays: []
|
|
199
214
|
}
|
|
200
215
|
};
|
|
201
|
-
for (const
|
|
202
|
-
|
|
203
|
-
const
|
|
216
|
+
for (const r of a)
|
|
217
|
+
r.uint8Array && (r.isDecode ? (t.decode.names.push(r.name), t.decode.uint8Arrays.push(r.uint8Array)) : (t.noDecode.names.push(r.name), t.noDecode.uint8Arrays.push(r.uint8Array)));
|
|
218
|
+
const s = await Promise.all([
|
|
204
219
|
this._executeMultipleParams(e, t.noDecode.names, t.noDecode.uint8Arrays, !1),
|
|
205
220
|
this._executeMultipleParams(e, t.decode.names, t.decode.uint8Arrays, !0)
|
|
206
|
-
]),
|
|
207
|
-
for (let
|
|
208
|
-
|
|
209
|
-
return
|
|
210
|
-
}
|
|
211
|
-
async _executeMultipleParams(e, a,
|
|
212
|
-
const
|
|
213
|
-
if (!
|
|
214
|
-
return
|
|
215
|
-
const
|
|
216
|
-
let
|
|
217
|
-
for (let
|
|
221
|
+
]), n = [];
|
|
222
|
+
for (let r = 0; r < s[0].length; r++)
|
|
223
|
+
n.push({ ...s[0][r], ...s[1][r] });
|
|
224
|
+
return n;
|
|
225
|
+
}
|
|
226
|
+
async _executeMultipleParams(e, a, i, t = !1) {
|
|
227
|
+
const s = Array(e.length);
|
|
228
|
+
if (!i.length)
|
|
229
|
+
return s;
|
|
230
|
+
const n = await this.handleMultipleParams(e, i, t);
|
|
231
|
+
let r = 0;
|
|
232
|
+
for (let o = 0; o < e.length; o++) {
|
|
218
233
|
const u = {};
|
|
219
234
|
for (const d of a) {
|
|
220
|
-
const h = r
|
|
235
|
+
const h = n[r++];
|
|
221
236
|
h.length && (u[d] = h);
|
|
222
237
|
}
|
|
223
|
-
|
|
238
|
+
s[o] = u;
|
|
224
239
|
}
|
|
225
|
-
return
|
|
240
|
+
return s;
|
|
226
241
|
}
|
|
227
|
-
|
|
228
|
-
return
|
|
242
|
+
fileEncrypt(e) {
|
|
243
|
+
return this.#t.file_encrypt(e);
|
|
229
244
|
}
|
|
230
|
-
|
|
231
|
-
return
|
|
245
|
+
filesEncrypt(e) {
|
|
246
|
+
return this.#t.files_encrypt(e);
|
|
232
247
|
}
|
|
233
248
|
}
|
|
234
249
|
class _ {
|
|
@@ -264,6 +279,6 @@ class _ {
|
|
|
264
279
|
}
|
|
265
280
|
}
|
|
266
281
|
export {
|
|
267
|
-
|
|
282
|
+
m as B,
|
|
268
283
|
_ as b
|
|
269
284
|
};
|