template-replacement 3.3.3 → 3.4.0
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/.editorconfig +8 -0
- package/.oxfmtrc.jsonc +7 -0
- package/.oxlintrc.json +3 -0
- package/README.md +39 -9
- package/core/base.ts +54 -55
- package/core/general.ts +37 -9
- package/core/sign.ts +43 -8
- package/dispatcher/general.ts +2 -1
- package/dispatcher/sign.ts +2 -1
- package/dispatcher/workerGeneral.ts +1 -1
- package/dispatcher/workerSign.ts +1 -1
- package/dist/base-DQz39fXI.js +249 -0
- package/dist/index-oILo_kXG.js +46 -0
- package/dist/main/general.js +1334 -1384
- package/dist/main/sign.js +1476 -1514
- package/dist/replace/general.js +283 -313
- package/dist/replace/sign.js +309 -327
- package/download/index.ts +13 -13
- package/download/stream.ts +29 -28
- package/eslint.config.ts +28 -0
- package/fileSystem/db/index.ts +25 -25
- package/fileSystem/db/indexedDBCache.ts +145 -143
- package/fileSystem/index.ts +5 -8
- package/fileSystem/interface.ts +4 -5
- package/fileSystem/opfs/index.ts +40 -36
- package/helper/index.ts +136 -125
- package/index.ts +6 -6
- package/office/zip.ts +106 -97
- package/package.json +14 -8
- package/replace/base.ts +203 -222
- package/replace/general.ts +44 -24
- package/replace/image.ts +88 -90
- package/replace/interface.ts +29 -24
- package/replace/paramsData.ts +107 -95
- package/replace/sign.ts +79 -52
- package/task/urlDownloadTask.ts +53 -55
- package/temp/index.ts +139 -124
- package/temp/interface.ts +8 -8
- package/tsconfig.json +1 -1
- package/vite.config.ts +11 -14
- package/worker/child/agency.ts +49 -41
- package/worker/child/base.ts +125 -89
- package/worker/child/general.ts +2 -3
- package/worker/child/sign.ts +4 -4
- package/worker/index.ts +52 -53
- package/worker/interface.ts +9 -6
- package/worker/main/general.ts +5 -5
- package/worker/main/index.ts +191 -66
- package/worker/main/sign.ts +5 -5
- package/worker/type.ts +16 -15
- package/dist/assets/template_replacement_core_wasm_bg.wasm +0 -0
- package/dist/assets/template_replacement_sign_core_wasm_bg.wasm +0 -0
- package/dist/base-CJv023nf.js +0 -284
- package/dist/general.d.ts +0 -1
- package/dist/index-tFDVIkZX.js +0 -46
- package/dist/sign.d.ts +0 -1
package/replace/image.ts
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
1
|
-
// import { add_media } from "template-replacement-core-wasm"
|
|
2
|
-
|
|
3
1
|
export function pxToEMU(px: number): number {
|
|
4
|
-
|
|
2
|
+
return px * (914400 / 96)
|
|
5
3
|
}
|
|
6
4
|
|
|
7
5
|
export function cmToEMU(cm: number): number {
|
|
8
|
-
|
|
6
|
+
return cm * 914400
|
|
9
7
|
}
|
|
10
8
|
|
|
11
9
|
export enum textWrapTypes {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
embed = 'Embed', //嵌入型
|
|
11
|
+
belowText = 'BelowText', //嵌于文字下方
|
|
12
|
+
aboveText = 'AboveText', //嵌于文字上方
|
|
15
13
|
}
|
|
16
14
|
|
|
17
15
|
function getFileExtension(filename: string): string {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
const ext = filename.split('.').pop()
|
|
17
|
+
if (ext === undefined) {
|
|
18
|
+
return ''
|
|
19
|
+
}
|
|
20
|
+
return '.' + ext
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
// async function generateId(file: Blob): Promise<string> {
|
|
@@ -28,101 +26,101 @@ function getFileExtension(filename: string): string {
|
|
|
28
26
|
// }
|
|
29
27
|
|
|
30
28
|
export type extent = {
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
cy: number
|
|
30
|
+
cx: number
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
//图片替换
|
|
36
34
|
export default class image {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
file: Blob
|
|
36
|
+
relationship = 'image'
|
|
37
|
+
id?: string
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
wpExtent?: extent //图片宽高
|
|
40
|
+
textWrap = textWrapTypes.embed //文字环绕
|
|
43
41
|
|
|
44
|
-
|
|
42
|
+
private _awaitInitQueue?: ((value?: unknown) => void)[] = []
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
44
|
+
constructor(file: Blob) {
|
|
45
|
+
if (file instanceof Blob) {
|
|
46
|
+
this.file = file
|
|
47
|
+
this.init()
|
|
48
|
+
} else {
|
|
49
|
+
throw new Error('不支持的数据类型')
|
|
53
50
|
}
|
|
51
|
+
}
|
|
54
52
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
delete this.awaitInitQueue
|
|
53
|
+
async init(): Promise<void> {
|
|
54
|
+
this._awaitInitQueue = []
|
|
55
|
+
await this.getExtent()
|
|
56
|
+
for (const resolve of this._awaitInitQueue) {
|
|
57
|
+
resolve()
|
|
62
58
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
59
|
+
this._awaitInitQueue = undefined
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// async generateId(): Promise<string> {
|
|
63
|
+
// this.id = await generateId(this.file)
|
|
64
|
+
// return this.id
|
|
65
|
+
// }
|
|
66
|
+
|
|
67
|
+
async awaitInit(): Promise<void> {
|
|
68
|
+
if (this._awaitInitQueue) {
|
|
69
|
+
await new Promise((resolve) => {
|
|
70
|
+
this._awaitInitQueue?.push(resolve)
|
|
71
|
+
})
|
|
75
72
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
if (!this.wpExtent) {
|
|
92
|
-
this.setPxExtent(0, 0)
|
|
93
|
-
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async getExtent(): Promise<extent> {
|
|
76
|
+
if (!this.wpExtent) {
|
|
77
|
+
if (this.file.size) {
|
|
78
|
+
try {
|
|
79
|
+
const bitmap = await createImageBitmap(this.file)
|
|
80
|
+
if (this.wpExtent) {
|
|
81
|
+
this.setPxExtent(bitmap.width, bitmap.height)
|
|
82
|
+
}
|
|
83
|
+
bitmap.close()
|
|
84
|
+
return this.wpExtent!
|
|
85
|
+
} catch (error) {
|
|
86
|
+
console.error(error)
|
|
94
87
|
}
|
|
95
|
-
|
|
88
|
+
}
|
|
89
|
+
if (!this.wpExtent) {
|
|
90
|
+
this.setPxExtent(0, 0)
|
|
91
|
+
}
|
|
96
92
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
93
|
+
return this.wpExtent!
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
//设置图片范围(像素)
|
|
97
|
+
setPxExtent(width: number, height: number): void {
|
|
98
|
+
this.wpExtent = {
|
|
99
|
+
cy: pxToEMU(height),
|
|
100
|
+
cx: pxToEMU(width),
|
|
104
101
|
}
|
|
102
|
+
}
|
|
105
103
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
104
|
+
//设置图片范围(厘米)
|
|
105
|
+
setCmExtent(width: number, height: number): void {
|
|
106
|
+
this.wpExtent = {
|
|
107
|
+
cy: cmToEMU(height),
|
|
108
|
+
cx: cmToEMU(width),
|
|
112
109
|
}
|
|
110
|
+
}
|
|
113
111
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
return data
|
|
112
|
+
async outJson(): Promise<Record<string, unknown>> {
|
|
113
|
+
await this.awaitInit()
|
|
114
|
+
const data: Record<string, unknown> = {}
|
|
115
|
+
for (const key in this) {
|
|
116
|
+
data[key] = this[key]
|
|
121
117
|
}
|
|
118
|
+
return data
|
|
119
|
+
}
|
|
122
120
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
121
|
+
setProperties(data: Record<string, unknown>) {
|
|
122
|
+
for (const key in data) {
|
|
123
|
+
this[key as keyof image] = data[key] as never;
|
|
127
124
|
}
|
|
128
|
-
}
|
|
125
|
+
}
|
|
126
|
+
}
|
package/replace/interface.ts
CHANGED
|
@@ -1,37 +1,42 @@
|
|
|
1
|
-
import paramsData from
|
|
2
|
-
import Temp from
|
|
1
|
+
import paramsData from './paramsData'
|
|
2
|
+
import Temp from '../temp'
|
|
3
3
|
|
|
4
4
|
export type media = {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
id: string
|
|
6
|
+
data: Uint8Array
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export default interface ReplaceInterface {
|
|
10
|
+
//添加模板文件
|
|
11
|
+
addTempFile(tempFile: Temp): void
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
//清空文件和链接
|
|
14
|
+
clear(): void
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
//提取变量
|
|
17
|
+
extractVariables(files: Temp[] | undefined): Promise<Record<string, string[]>>
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
//提取媒体
|
|
20
|
+
extractMedias(files: Temp[] | undefined): Promise<Record<string, media[]>>
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
//签名方法
|
|
23
|
+
sign(data: unknown): Promise<string>
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
//执行替换任务
|
|
26
|
+
execute(
|
|
27
|
+
params: paramsData,
|
|
28
|
+
files: Temp[] | undefined,
|
|
29
|
+
): Promise<Record<string, Uint8Array>>
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
//执行替换任务(多套参数)
|
|
32
|
+
executeMultipleParams(
|
|
33
|
+
params: paramsData[],
|
|
34
|
+
files: Temp[] | undefined,
|
|
35
|
+
): Promise<Record<string, Uint8Array>[]>
|
|
28
36
|
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
//文件加密
|
|
38
|
+
fileEncrypt(file: Uint8Array): Promise<Uint8Array>
|
|
31
39
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
//文件批量加密
|
|
36
|
-
filesEncrypt(files: (Uint8Array)[]): Promise<(Uint8Array)[]>
|
|
37
|
-
}
|
|
40
|
+
//文件批量加密
|
|
41
|
+
filesEncrypt(files: Uint8Array[]): Promise<Uint8Array[]>
|
|
42
|
+
}
|
package/replace/paramsData.ts
CHANGED
|
@@ -1,116 +1,128 @@
|
|
|
1
1
|
import image, { extent, textWrapTypes } from './image'
|
|
2
2
|
|
|
3
|
-
export type textData = Record<string, string|image>
|
|
3
|
+
export type textData = Record<string, string | image>
|
|
4
4
|
export type mediaData = Record<string, image>
|
|
5
5
|
|
|
6
6
|
type imageValue = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
id: string
|
|
8
|
+
index: number
|
|
9
|
+
suffix: string
|
|
10
|
+
wp_extent: extent
|
|
11
|
+
text_wrap: textWrapTypes
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
type value = {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
Image?: imageValue
|
|
16
|
+
Text?: string
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export type replaceParams = {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
text: Record<string, value>
|
|
21
|
+
media: Record<string, value>
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export default class paramsData {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
textData: textData = {}
|
|
26
|
+
mediaData: mediaData = {}
|
|
27
|
+
add_media?: (file: Uint8Array) => string
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
if (media && media.constructor === Object) {
|
|
34
|
-
this.mediaData = media
|
|
35
|
-
}
|
|
29
|
+
constructor(text?: textData, media?: mediaData) {
|
|
30
|
+
if (text && text.constructor === Object) {
|
|
31
|
+
this.textData = text
|
|
36
32
|
}
|
|
33
|
+
if (media && media.constructor === Object) {
|
|
34
|
+
this.mediaData = media
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (value instanceof image) {
|
|
80
|
-
let id = value.id ?? ''
|
|
81
|
-
let index = 0
|
|
82
|
-
if (!id) {
|
|
83
|
-
const buffer = await value.file.arrayBuffer()
|
|
84
|
-
const uint8Array = new Uint8Array(buffer)
|
|
38
|
+
//转为替换参数
|
|
39
|
+
async toReplaceParams(
|
|
40
|
+
mediaBuffers: Uint8Array[] = [],
|
|
41
|
+
): Promise<[replaceParams, Uint8Array[]]> {
|
|
42
|
+
const text: Record<string, value> = {}
|
|
43
|
+
const media: Record<string, value> = {}
|
|
44
|
+
const tasks = []
|
|
45
|
+
for (const key in this.textData) {
|
|
46
|
+
tasks.push(
|
|
47
|
+
new Promise<void>(async (resolve) => {
|
|
48
|
+
const value = this.textData[key]
|
|
49
|
+
if (value instanceof image) {
|
|
50
|
+
let id = value.id ?? ''
|
|
51
|
+
let index = 0
|
|
52
|
+
if (!id) {
|
|
53
|
+
const buffer = await value.file.arrayBuffer()
|
|
54
|
+
const uint8Array = new Uint8Array(buffer)
|
|
55
|
+
if (this.add_media) {
|
|
56
|
+
id = this.add_media(uint8Array)
|
|
57
|
+
} else {
|
|
58
|
+
index = mediaBuffers.push(uint8Array) - 1
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
text[key] = {
|
|
62
|
+
Image: {
|
|
63
|
+
index,
|
|
64
|
+
id,
|
|
65
|
+
suffix: '',
|
|
66
|
+
wp_extent: value.wpExtent ?? { cx: 0, cy: 0 },
|
|
67
|
+
text_wrap: value.textWrap,
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
text[key] = {
|
|
72
|
+
Text: String(value),
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
resolve()
|
|
76
|
+
}),
|
|
77
|
+
)
|
|
78
|
+
}
|
|
85
79
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
suffix: '',
|
|
97
|
-
wp_extent: value.wpExtent ?? {cx: 0, cy: 0},
|
|
98
|
-
text_wrap: value.textWrap
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
resolve()
|
|
103
|
-
}))
|
|
104
|
-
}
|
|
80
|
+
for (const key in this.mediaData) {
|
|
81
|
+
tasks.push(
|
|
82
|
+
new Promise<void>(async (resolve) => {
|
|
83
|
+
const value = this.mediaData[key]
|
|
84
|
+
if (value instanceof image) {
|
|
85
|
+
let id = value.id ?? ''
|
|
86
|
+
let index = 0
|
|
87
|
+
if (!id) {
|
|
88
|
+
const buffer = await value.file.arrayBuffer()
|
|
89
|
+
const uint8Array = new Uint8Array(buffer)
|
|
105
90
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
91
|
+
if (this.add_media) {
|
|
92
|
+
id = this.add_media(uint8Array)
|
|
93
|
+
} else {
|
|
94
|
+
index = mediaBuffers.push(uint8Array) - 1
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
media[key] = {
|
|
98
|
+
Image: {
|
|
99
|
+
index,
|
|
100
|
+
id,
|
|
101
|
+
suffix: '',
|
|
102
|
+
wp_extent: value.wpExtent ?? { cx: 0, cy: 0 },
|
|
103
|
+
text_wrap: value.textWrap,
|
|
104
|
+
},
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
resolve()
|
|
108
|
+
}),
|
|
109
|
+
)
|
|
111
110
|
}
|
|
112
111
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
await Promise.all(tasks)
|
|
113
|
+
return [
|
|
114
|
+
{
|
|
115
|
+
text,
|
|
116
|
+
media,
|
|
117
|
+
},
|
|
118
|
+
mediaBuffers,
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
isEmpty() {
|
|
123
|
+
return (
|
|
124
|
+
Object.keys(this.textData).length === 0 &&
|
|
125
|
+
Object.keys(this.mediaData).length === 0
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
}
|
package/replace/sign.ts
CHANGED
|
@@ -1,61 +1,88 @@
|
|
|
1
|
-
import Base from './base'
|
|
2
|
-
import core, {
|
|
3
|
-
|
|
1
|
+
import Base from './base'
|
|
2
|
+
import core, {
|
|
3
|
+
add_media,
|
|
4
|
+
add_template,
|
|
5
|
+
replace_batch,
|
|
6
|
+
replace_params_encode,
|
|
7
|
+
replace_batch_multiple_params,
|
|
8
|
+
replace_params_encode_multiple_params,
|
|
9
|
+
} from '../core/sign'
|
|
10
|
+
import paramsData, { replaceParams } from './paramsData'
|
|
4
11
|
|
|
5
12
|
export default class Sign extends Base {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
async handle(paramsData: paramsData, files: Uint8Array[], isDecode: boolean = false): Promise<Uint8Array[]> {
|
|
11
|
-
paramsData.add_media = add_media
|
|
12
|
-
|
|
13
|
-
const addFileTasks: Promise<number>[] = []
|
|
14
|
-
for (const file of files) {
|
|
15
|
-
addFileTasks.push(add_template(file, isDecode))
|
|
16
|
-
}
|
|
17
|
-
const [tempFiles, [variables]] = await Promise.all([
|
|
18
|
-
Promise.all(addFileTasks),
|
|
19
|
-
paramsData.toReplaceParams(),
|
|
20
|
-
])
|
|
21
|
-
const encodeData = {
|
|
22
|
-
files: tempFiles,
|
|
23
|
-
variables
|
|
24
|
-
}
|
|
13
|
+
constructor() {
|
|
14
|
+
super(core())
|
|
15
|
+
}
|
|
25
16
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
async handle(
|
|
18
|
+
paramsData: paramsData,
|
|
19
|
+
files: Uint8Array[],
|
|
20
|
+
encode_files: Uint8Array[],
|
|
21
|
+
): Promise<Uint8Array[]> {
|
|
22
|
+
paramsData.add_media = add_media
|
|
23
|
+
const addFileTasks: Promise<number>[] = []
|
|
24
|
+
for (const file of files) {
|
|
25
|
+
addFileTasks.push(add_template(file, false))
|
|
29
26
|
}
|
|
27
|
+
for (const file of encode_files) {
|
|
28
|
+
addFileTasks.push(add_template(file, true))
|
|
29
|
+
}
|
|
30
|
+
const [tempFiles, [variables]] = await Promise.all([
|
|
31
|
+
Promise.all(addFileTasks),
|
|
32
|
+
paramsData.toReplaceParams(),
|
|
33
|
+
])
|
|
34
|
+
const encodeData = {
|
|
35
|
+
files: tempFiles,
|
|
36
|
+
variables,
|
|
37
|
+
}
|
|
38
|
+
const paramsEncode = await replace_params_encode(encodeData)
|
|
39
|
+
const verifyCode = await this.sign(paramsEncode)
|
|
40
|
+
return replace_batch(verifyCode, paramsEncode.data)
|
|
41
|
+
}
|
|
30
42
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
async handleMultipleParams(
|
|
44
|
+
paramsList: paramsData[],
|
|
45
|
+
files: Uint8Array[],
|
|
46
|
+
encode_files: Uint8Array[],
|
|
47
|
+
): Promise<Uint8Array[]> {
|
|
48
|
+
let variablesTasks: Promise<replaceParams>[] = []
|
|
49
|
+
for (const paramsData of paramsList) {
|
|
50
|
+
paramsData.add_media = add_media
|
|
51
|
+
variablesTasks.push(
|
|
52
|
+
new Promise((resolve, reject) => {
|
|
53
|
+
paramsData
|
|
54
|
+
.toReplaceParams()
|
|
55
|
+
.then(([params]) => {
|
|
56
|
+
resolve(params)
|
|
57
|
+
})
|
|
58
|
+
.catch(reject)
|
|
59
|
+
}),
|
|
60
|
+
)
|
|
61
|
+
}
|
|
46
62
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
63
|
+
const addFileTasks: Promise<number>[] = []
|
|
64
|
+
for (const file of files) {
|
|
65
|
+
addFileTasks.push(add_template(file, false))
|
|
66
|
+
}
|
|
67
|
+
for (const file of encode_files) {
|
|
68
|
+
addFileTasks.push(add_template(file, true))
|
|
69
|
+
}
|
|
51
70
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
71
|
+
const [tempFiles, variables] = await Promise.all([
|
|
72
|
+
Promise.all(addFileTasks),
|
|
73
|
+
Promise.all(variablesTasks),
|
|
74
|
+
])
|
|
56
75
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
76
|
+
const encodeData = {
|
|
77
|
+
files: tempFiles,
|
|
78
|
+
variables,
|
|
60
79
|
}
|
|
61
|
-
|
|
80
|
+
|
|
81
|
+
const paramsEncode = await replace_params_encode_multiple_params(encodeData)
|
|
82
|
+
const verifyCode = await this.sign(paramsEncode)
|
|
83
|
+
return replace_batch_multiple_params(
|
|
84
|
+
verifyCode,
|
|
85
|
+
paramsEncode.data,
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
}
|