@makarandkate/ezo-connect-wa 7.0.5 → 7.0.7
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/lib/h2i.d.ts +1 -0
- package/lib/h2i.d.ts.map +1 -1
- package/lib/h2i.js +36 -3
- package/lib/h2i.js.map +1 -1
- package/lib/server.js +2 -2
- package/lib/server.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/whatsapp.d.ts +2 -1
- package/lib/whatsapp.d.ts.map +1 -1
- package/lib/whatsapp.js +1 -0
- package/lib/whatsapp.js.map +1 -1
- package/package.json +3 -1
- package/src/h2i.ts +331 -293
- package/src/server.ts +2 -2
- package/src/whatsapp.ts +2 -1
package/src/h2i.ts
CHANGED
|
@@ -1,28 +1,62 @@
|
|
|
1
1
|
import request from 'request';
|
|
2
2
|
import { Utils } from './utils';
|
|
3
|
+
import { createCanvas, loadImage } from "canvas";
|
|
4
|
+
import fetch from "node-fetch";
|
|
3
5
|
export class H2I {
|
|
4
6
|
|
|
7
|
+
public static async isImageBlank(imgUrl: string) {
|
|
8
|
+
const img = await loadImage(imgUrl);
|
|
9
|
+
const width = img.width;
|
|
10
|
+
const height = img.height;
|
|
11
|
+
|
|
12
|
+
const canvas = createCanvas(width, height);
|
|
13
|
+
const ctx = canvas.getContext("2d");
|
|
14
|
+
|
|
15
|
+
ctx.drawImage(img, 0, 0, width, height);
|
|
16
|
+
const minSide = Math.min(width, height);
|
|
17
|
+
const colors = [];
|
|
18
|
+
// Bottom-left (x=0, y=height-1) → Top-right (x=width-1, y=0)
|
|
19
|
+
for (let i = 0; i < minSide; i++) {
|
|
20
|
+
const x = i;
|
|
21
|
+
const y = height - 1 - i;
|
|
22
|
+
const pixel = ctx.getImageData(x, y, 1, 1).data;
|
|
23
|
+
colors.push([pixel[0], pixel[1], pixel[2]]); // RGB
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const tolerance = 10;
|
|
27
|
+
const ref = colors[0];
|
|
28
|
+
const isSimilar = (a: any, b: any) =>
|
|
29
|
+
Math.abs(a[0] - b[0]) < tolerance &&
|
|
30
|
+
Math.abs(a[1] - b[1]) < tolerance &&
|
|
31
|
+
Math.abs(a[2] - b[2]) < tolerance;
|
|
32
|
+
|
|
33
|
+
const matches = colors.filter(c => isSimilar(c, ref));
|
|
34
|
+
const ratio = matches.length / colors.length;
|
|
35
|
+
|
|
36
|
+
return ratio >= 0.98;
|
|
37
|
+
}
|
|
38
|
+
|
|
5
39
|
public static getImg(config: {
|
|
6
40
|
html: string,
|
|
7
|
-
bucketId
|
|
8
|
-
waitTime?:number,
|
|
9
|
-
transparentBg?:boolean,
|
|
10
|
-
type?:'png'|'jpg',
|
|
11
|
-
debug?:boolean
|
|
12
|
-
}):Promise<string> {
|
|
13
|
-
return new Promise(async (resolve)=>{
|
|
14
|
-
let url=await this.getImgTryOnce(config)
|
|
15
|
-
if(url?.length){
|
|
41
|
+
bucketId: number,
|
|
42
|
+
waitTime?: number,
|
|
43
|
+
transparentBg?: boolean,
|
|
44
|
+
type?: 'png' | 'jpg',
|
|
45
|
+
debug?: boolean
|
|
46
|
+
}): Promise<string> {
|
|
47
|
+
return new Promise(async (resolve) => {
|
|
48
|
+
let url = await this.getImgTryOnce(config)
|
|
49
|
+
if (url?.length) {
|
|
16
50
|
return resolve(url);
|
|
17
51
|
}
|
|
18
|
-
let retryMap:{[key:number]:number}={
|
|
19
|
-
50:10, 500:10, 1000:10, 2000:10, 5000:10, 20000:5
|
|
52
|
+
let retryMap: { [key: number]: number } = {
|
|
53
|
+
50: 10, 500: 10, 1000: 10, 2000: 10, 5000: 10, 20000: 5
|
|
20
54
|
}
|
|
21
|
-
for(let k in retryMap){
|
|
22
|
-
for(let i=0;i<Number(retryMap[k]);i++){
|
|
55
|
+
for (let k in retryMap) {
|
|
56
|
+
for (let i = 0; i < Number(retryMap[k]); i++) {
|
|
23
57
|
await Utils.wait(Number(k));
|
|
24
|
-
url=await this.getImgTryOnce(config)
|
|
25
|
-
if(url?.length){
|
|
58
|
+
url = await this.getImgTryOnce(config)
|
|
59
|
+
if (url?.length) {
|
|
26
60
|
return resolve(url);
|
|
27
61
|
}
|
|
28
62
|
}
|
|
@@ -37,56 +71,60 @@ export class H2I {
|
|
|
37
71
|
|
|
38
72
|
public static getImgTryOnce(config: {
|
|
39
73
|
html: string,
|
|
40
|
-
bucketId
|
|
41
|
-
waitTime?:number,
|
|
42
|
-
transparentBg?:boolean,
|
|
43
|
-
type?:'png'|'jpg',
|
|
44
|
-
debug
|
|
45
|
-
}):Promise<string> {
|
|
46
|
-
return new Promise((resolve)=>{
|
|
74
|
+
bucketId: number,
|
|
75
|
+
waitTime?: number,
|
|
76
|
+
transparentBg?: boolean,
|
|
77
|
+
type?: 'png' | 'jpg',
|
|
78
|
+
debug?: boolean
|
|
79
|
+
}): Promise<string> {
|
|
80
|
+
return new Promise((resolve) => {
|
|
47
81
|
request({
|
|
48
82
|
method: 'POST',
|
|
49
|
-
headers: {'Content-Type': 'application/json'},
|
|
50
|
-
url
|
|
51
|
-
body:JSON.stringify({
|
|
52
|
-
htmlStr:config.html,
|
|
53
|
-
waitTime:config?.waitTime || 0,
|
|
54
|
-
transparentBg:config?.transparentBg || false,
|
|
55
|
-
type:config?.type || 'png',
|
|
83
|
+
headers: { 'Content-Type': 'application/json' },
|
|
84
|
+
url: `https://mdh.ezobooks.in/html2image/${config?.bucketId}`,
|
|
85
|
+
body: JSON.stringify({
|
|
86
|
+
htmlStr: config.html,
|
|
87
|
+
waitTime: config?.waitTime || 0,
|
|
88
|
+
transparentBg: config?.transparentBg || false,
|
|
89
|
+
type: config?.type || 'png',
|
|
56
90
|
})
|
|
57
|
-
},(error,res)=>{
|
|
58
|
-
if(error){
|
|
59
|
-
if(config?.debug===true){console.error('H2I:95',error);}
|
|
91
|
+
}, async (error, res) => {
|
|
92
|
+
if (error) {
|
|
93
|
+
if (config?.debug === true) { console.error('H2I:95', error); }
|
|
60
94
|
return resolve('');
|
|
61
95
|
}
|
|
62
|
-
if(res?.body){
|
|
63
|
-
if(res?.body?.indexOf("502 Bad Gateway")
|
|
96
|
+
if (res?.body) {
|
|
97
|
+
if (res?.body?.indexOf("502 Bad Gateway") > -1) {
|
|
64
98
|
return resolve('');
|
|
65
99
|
}
|
|
66
100
|
|
|
67
|
-
if(res?.body?.indexOf("504 Gateway Time-out")
|
|
101
|
+
if (res?.body?.indexOf("504 Gateway Time-out") > -1) {
|
|
68
102
|
return resolve('');
|
|
69
103
|
}
|
|
70
104
|
|
|
71
|
-
if(res?.body?.indexOf("504 Gateway Timeout")
|
|
105
|
+
if (res?.body?.indexOf("504 Gateway Timeout") > -1) {
|
|
72
106
|
return resolve('');
|
|
73
107
|
}
|
|
74
|
-
|
|
75
|
-
try{
|
|
76
|
-
let obj=JSON.parse(res?.body);
|
|
77
|
-
if(obj?.status == 'success' && obj?.image?.length){
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
let obj = JSON.parse(res?.body);
|
|
111
|
+
if (obj?.status == 'success' && obj?.image?.length) {
|
|
78
112
|
let finalUrl = obj?.image.replace(/mdh.ezobooks/, 'mdi.ezobooks')?.replace(/md1.ezobooks/, 'mdi.ezobooks');
|
|
79
|
-
|
|
113
|
+
if(await this.isImageBlank(finalUrl)){
|
|
114
|
+
return resolve('');
|
|
115
|
+
}else{
|
|
116
|
+
return resolve(finalUrl);
|
|
117
|
+
}
|
|
80
118
|
|
|
81
|
-
}else{
|
|
82
|
-
if(config?.debug===true){console.error('H2I:105',obj);}
|
|
119
|
+
} else {
|
|
120
|
+
if (config?.debug === true) { console.error('H2I:105', obj); }
|
|
83
121
|
|
|
84
122
|
return resolve('');
|
|
85
123
|
|
|
86
124
|
}
|
|
87
|
-
}catch(err){
|
|
88
|
-
if(config?.debug===true){console.error('H2I:111',res?.body,err);}
|
|
89
|
-
|
|
125
|
+
} catch (err) {
|
|
126
|
+
if (config?.debug === true) { console.error('H2I:111', res?.body, err); }
|
|
127
|
+
|
|
90
128
|
return resolve('');
|
|
91
129
|
|
|
92
130
|
}
|
|
@@ -100,23 +138,23 @@ export class H2I {
|
|
|
100
138
|
|
|
101
139
|
public static getImgFromBase64(config: {
|
|
102
140
|
base64Str: string,
|
|
103
|
-
bucketId
|
|
104
|
-
type?:'png'|'jpg',
|
|
105
|
-
debug?:boolean
|
|
106
|
-
}):Promise<string> {
|
|
107
|
-
return new Promise(async (resolve)=>{
|
|
108
|
-
let url=await this.getImgFromBase64TryOnce(config)
|
|
109
|
-
if(url?.length){
|
|
141
|
+
bucketId: number,
|
|
142
|
+
type?: 'png' | 'jpg',
|
|
143
|
+
debug?: boolean
|
|
144
|
+
}): Promise<string> {
|
|
145
|
+
return new Promise(async (resolve) => {
|
|
146
|
+
let url = await this.getImgFromBase64TryOnce(config)
|
|
147
|
+
if (url?.length) {
|
|
110
148
|
return resolve(url);
|
|
111
149
|
}
|
|
112
|
-
let retryMap:{[key:number]:number}={
|
|
113
|
-
50:10, 500:10, 1000:10, 2000:10, 5000:10, 20000:5
|
|
150
|
+
let retryMap: { [key: number]: number } = {
|
|
151
|
+
50: 10, 500: 10, 1000: 10, 2000: 10, 5000: 10, 20000: 5
|
|
114
152
|
}
|
|
115
|
-
for(let k in retryMap){
|
|
116
|
-
for(let i=0;i<Number(retryMap[k]);i++){
|
|
153
|
+
for (let k in retryMap) {
|
|
154
|
+
for (let i = 0; i < Number(retryMap[k]); i++) {
|
|
117
155
|
await Utils.wait(Number(k));
|
|
118
|
-
url=await this.getImgFromBase64TryOnce(config)
|
|
119
|
-
if(url?.length){
|
|
156
|
+
url = await this.getImgFromBase64TryOnce(config)
|
|
157
|
+
if (url?.length) {
|
|
120
158
|
return resolve(url);
|
|
121
159
|
}
|
|
122
160
|
}
|
|
@@ -131,52 +169,52 @@ export class H2I {
|
|
|
131
169
|
|
|
132
170
|
public static getImgFromBase64TryOnce(config: {
|
|
133
171
|
base64Str: string,
|
|
134
|
-
bucketId
|
|
135
|
-
type?:'png'|'jpg',
|
|
136
|
-
debug
|
|
137
|
-
}):Promise<string> {
|
|
138
|
-
return new Promise((resolve)=>{
|
|
172
|
+
bucketId: number,
|
|
173
|
+
type?: 'png' | 'jpg',
|
|
174
|
+
debug?: boolean
|
|
175
|
+
}): Promise<string> {
|
|
176
|
+
return new Promise((resolve) => {
|
|
139
177
|
request({
|
|
140
178
|
method: 'POST',
|
|
141
|
-
headers: {'Content-Type': 'application/json'},
|
|
142
|
-
url
|
|
143
|
-
body:JSON.stringify({
|
|
144
|
-
base64Str:config.base64Str,
|
|
145
|
-
type:config?.type || 'png',
|
|
179
|
+
headers: { 'Content-Type': 'application/json' },
|
|
180
|
+
url: `https://mdh.ezobooks.in/base642image/${config?.bucketId}`,
|
|
181
|
+
body: JSON.stringify({
|
|
182
|
+
base64Str: config.base64Str,
|
|
183
|
+
type: config?.type || 'png',
|
|
146
184
|
})
|
|
147
|
-
},(error,res)=>{
|
|
148
|
-
if(error){
|
|
149
|
-
if(config?.debug===true){console.error('H2I:245',error);}
|
|
185
|
+
}, (error, res) => {
|
|
186
|
+
if (error) {
|
|
187
|
+
if (config?.debug === true) { console.error('H2I:245', error); }
|
|
150
188
|
return resolve('');
|
|
151
189
|
}
|
|
152
|
-
if(res?.body){
|
|
153
|
-
if(res?.body?.indexOf("502 Bad Gateway")
|
|
190
|
+
if (res?.body) {
|
|
191
|
+
if (res?.body?.indexOf("502 Bad Gateway") > -1) {
|
|
154
192
|
return resolve('');
|
|
155
193
|
}
|
|
156
194
|
|
|
157
|
-
if(res?.body?.indexOf("504 Gateway Time-out")
|
|
195
|
+
if (res?.body?.indexOf("504 Gateway Time-out") > -1) {
|
|
158
196
|
return resolve('');
|
|
159
197
|
}
|
|
160
198
|
|
|
161
|
-
if(res?.body?.indexOf("504 Gateway Timeout")
|
|
199
|
+
if (res?.body?.indexOf("504 Gateway Timeout") > -1) {
|
|
162
200
|
return resolve('');
|
|
163
201
|
}
|
|
164
|
-
|
|
165
|
-
try{
|
|
166
|
-
let obj=JSON.parse(res?.body);
|
|
167
|
-
if(obj?.status == 'success' && obj?.image?.length){
|
|
202
|
+
|
|
203
|
+
try {
|
|
204
|
+
let obj = JSON.parse(res?.body);
|
|
205
|
+
if (obj?.status == 'success' && obj?.image?.length) {
|
|
168
206
|
let finalUrl = obj?.image.replace(/mdh.ezobooks/, 'mdi.ezobooks')?.replace(/md1.ezobooks/, 'mdi.ezobooks');
|
|
169
207
|
return resolve(finalUrl);
|
|
170
208
|
|
|
171
|
-
}else{
|
|
172
|
-
if(config?.debug===true){console.error('H2I:268',obj);}
|
|
209
|
+
} else {
|
|
210
|
+
if (config?.debug === true) { console.error('H2I:268', obj); }
|
|
173
211
|
|
|
174
212
|
return resolve('');
|
|
175
213
|
|
|
176
214
|
}
|
|
177
|
-
}catch(err){
|
|
178
|
-
if(config?.debug===true){console.error('H2I:274',res?.body,err);}
|
|
179
|
-
|
|
215
|
+
} catch (err) {
|
|
216
|
+
if (config?.debug === true) { console.error('H2I:274', res?.body, err); }
|
|
217
|
+
|
|
180
218
|
return resolve('');
|
|
181
219
|
|
|
182
220
|
}
|
|
@@ -191,22 +229,22 @@ export class H2I {
|
|
|
191
229
|
public static getPdf(config: {
|
|
192
230
|
html: string,
|
|
193
231
|
bucketId: number,
|
|
194
|
-
waitTime?:number,
|
|
195
|
-
debug?:boolean
|
|
196
|
-
}):Promise<string> {
|
|
197
|
-
return new Promise(async (resolve)=>{
|
|
198
|
-
let url=await this.getPdfTryOnce(config)
|
|
199
|
-
if(url?.length){
|
|
232
|
+
waitTime?: number,
|
|
233
|
+
debug?: boolean
|
|
234
|
+
}): Promise<string> {
|
|
235
|
+
return new Promise(async (resolve) => {
|
|
236
|
+
let url = await this.getPdfTryOnce(config)
|
|
237
|
+
if (url?.length) {
|
|
200
238
|
return resolve(url);
|
|
201
239
|
}
|
|
202
|
-
let retryMap:{[key:number]:number}={
|
|
203
|
-
50:10, 500:10, 1000:10, 2000:10, 5000:10, 20000:5
|
|
240
|
+
let retryMap: { [key: number]: number } = {
|
|
241
|
+
50: 10, 500: 10, 1000: 10, 2000: 10, 5000: 10, 20000: 5
|
|
204
242
|
}
|
|
205
|
-
for(let k in retryMap){
|
|
206
|
-
for(let i=0;i<Number(retryMap[k]);i++){
|
|
243
|
+
for (let k in retryMap) {
|
|
244
|
+
for (let i = 0; i < Number(retryMap[k]); i++) {
|
|
207
245
|
await Utils.wait(Number(k));
|
|
208
|
-
url=await this.getPdfTryOnce(config)
|
|
209
|
-
if(url?.length){
|
|
246
|
+
url = await this.getPdfTryOnce(config)
|
|
247
|
+
if (url?.length) {
|
|
210
248
|
return resolve(url);
|
|
211
249
|
}
|
|
212
250
|
}
|
|
@@ -220,43 +258,43 @@ export class H2I {
|
|
|
220
258
|
|
|
221
259
|
public static getPdfTryOnce(config: {
|
|
222
260
|
html: string,
|
|
223
|
-
bucketId
|
|
224
|
-
waitTime?:number,
|
|
225
|
-
debug
|
|
226
|
-
}):Promise<string> {
|
|
227
|
-
return new Promise((resolve)=>{
|
|
261
|
+
bucketId: number,
|
|
262
|
+
waitTime?: number,
|
|
263
|
+
debug?: boolean
|
|
264
|
+
}): Promise<string> {
|
|
265
|
+
return new Promise((resolve) => {
|
|
228
266
|
request({
|
|
229
267
|
method: 'POST',
|
|
230
|
-
headers: {'Content-Type': 'application/json'},
|
|
231
|
-
url
|
|
232
|
-
body:JSON.stringify({
|
|
233
|
-
htmlStr:config.html,
|
|
234
|
-
waitTime:config?.waitTime || 0
|
|
268
|
+
headers: { 'Content-Type': 'application/json' },
|
|
269
|
+
url: `https://mdh.ezobooks.in/html2pdf/${config.bucketId}`,
|
|
270
|
+
body: JSON.stringify({
|
|
271
|
+
htmlStr: config.html,
|
|
272
|
+
waitTime: config?.waitTime || 0
|
|
235
273
|
})
|
|
236
|
-
},(error,res)=>{
|
|
237
|
-
if(error){
|
|
238
|
-
if(config?.debug===true){console.error('H2I:262',error);}
|
|
274
|
+
}, (error, res) => {
|
|
275
|
+
if (error) {
|
|
276
|
+
if (config?.debug === true) { console.error('H2I:262', error); }
|
|
239
277
|
return resolve('');
|
|
240
278
|
}
|
|
241
|
-
if(res?.body){
|
|
242
|
-
if(res?.body?.indexOf("502 Bad Gateway")>0){
|
|
279
|
+
if (res?.body) {
|
|
280
|
+
if (res?.body?.indexOf("502 Bad Gateway") > 0) {
|
|
243
281
|
return resolve('');
|
|
244
282
|
}
|
|
245
|
-
try{
|
|
246
|
-
let obj=JSON.parse(res?.body);
|
|
247
|
-
if(obj?.status == 'success' && obj?.image?.length){
|
|
283
|
+
try {
|
|
284
|
+
let obj = JSON.parse(res?.body);
|
|
285
|
+
if (obj?.status == 'success' && obj?.image?.length) {
|
|
248
286
|
let finalUrl = obj?.image.replace(/mdh.ezobooks/, 'mdi.ezobooks')?.replace(/md1.ezobooks/, 'mdi.ezobooks');
|
|
249
287
|
return resolve(finalUrl);
|
|
250
288
|
|
|
251
|
-
}else{
|
|
252
|
-
if(config?.debug===true){console.error('H2I:272',obj);}
|
|
289
|
+
} else {
|
|
290
|
+
if (config?.debug === true) { console.error('H2I:272', obj); }
|
|
253
291
|
|
|
254
292
|
return resolve('');
|
|
255
293
|
|
|
256
294
|
}
|
|
257
|
-
}catch(err){
|
|
258
|
-
if(config?.debug===true){console.error('H2I:278',err);}
|
|
259
|
-
|
|
295
|
+
} catch (err) {
|
|
296
|
+
if (config?.debug === true) { console.error('H2I:278', err); }
|
|
297
|
+
|
|
260
298
|
return resolve('');
|
|
261
299
|
|
|
262
300
|
}
|
|
@@ -270,24 +308,24 @@ export class H2I {
|
|
|
270
308
|
|
|
271
309
|
public static getVid(config: {
|
|
272
310
|
videoUrl: string,
|
|
273
|
-
frameUrl:string,
|
|
274
|
-
contactImageUrl:string,
|
|
275
|
-
requestId:string,
|
|
276
|
-
debug?:boolean
|
|
277
|
-
}):Promise<string> {
|
|
278
|
-
return new Promise(async (resolve)=>{
|
|
279
|
-
let url=await this.getVidTryOnce(config)
|
|
280
|
-
if(url?.length){
|
|
311
|
+
frameUrl: string,
|
|
312
|
+
contactImageUrl: string,
|
|
313
|
+
requestId: string,
|
|
314
|
+
debug?: boolean
|
|
315
|
+
}): Promise<string> {
|
|
316
|
+
return new Promise(async (resolve) => {
|
|
317
|
+
let url = await this.getVidTryOnce(config)
|
|
318
|
+
if (url?.length) {
|
|
281
319
|
return resolve(url);
|
|
282
320
|
}
|
|
283
|
-
let retryMap:{[key:number]:number}={
|
|
284
|
-
50:10, 500:10, 1000:10, 2000:10, 5000:10, 20000:5
|
|
321
|
+
let retryMap: { [key: number]: number } = {
|
|
322
|
+
50: 10, 500: 10, 1000: 10, 2000: 10, 5000: 10, 20000: 5
|
|
285
323
|
}
|
|
286
|
-
for(let k in retryMap){
|
|
287
|
-
for(let i=0;i<Number(retryMap[k]);i++){
|
|
324
|
+
for (let k in retryMap) {
|
|
325
|
+
for (let i = 0; i < Number(retryMap[k]); i++) {
|
|
288
326
|
await Utils.wait(Number(k));
|
|
289
|
-
url=await this.getVidTryOnce(config)
|
|
290
|
-
if(url?.length){
|
|
327
|
+
url = await this.getVidTryOnce(config)
|
|
328
|
+
if (url?.length) {
|
|
291
329
|
return resolve(url);
|
|
292
330
|
}
|
|
293
331
|
}
|
|
@@ -301,43 +339,43 @@ export class H2I {
|
|
|
301
339
|
|
|
302
340
|
public static getVidTryOnce(config: {
|
|
303
341
|
videoUrl: string,
|
|
304
|
-
frameUrl:string,
|
|
305
|
-
contactImageUrl:string,
|
|
306
|
-
requestId:string,
|
|
307
|
-
debug?:boolean
|
|
308
|
-
}):Promise<string> {
|
|
309
|
-
return new Promise((resolve)=>{
|
|
342
|
+
frameUrl: string,
|
|
343
|
+
contactImageUrl: string,
|
|
344
|
+
requestId: string,
|
|
345
|
+
debug?: boolean
|
|
346
|
+
}): Promise<string> {
|
|
347
|
+
return new Promise((resolve) => {
|
|
310
348
|
request({
|
|
311
349
|
method: 'POST',
|
|
312
|
-
headers: {'Content-Type': 'application/json'},
|
|
313
|
-
url
|
|
314
|
-
body:JSON.stringify({
|
|
315
|
-
videoUrl:config.videoUrl,
|
|
316
|
-
frameUrl:config.frameUrl,
|
|
317
|
-
contactImageUrl:config.contactImageUrl,
|
|
318
|
-
requestId:config.requestId,
|
|
350
|
+
headers: { 'Content-Type': 'application/json' },
|
|
351
|
+
url: `https://mdh.ezobooks.in/vd/compile`,
|
|
352
|
+
body: JSON.stringify({
|
|
353
|
+
videoUrl: config.videoUrl,
|
|
354
|
+
frameUrl: config.frameUrl,
|
|
355
|
+
contactImageUrl: config.contactImageUrl,
|
|
356
|
+
requestId: config.requestId,
|
|
319
357
|
})
|
|
320
|
-
},(error,res)=>{
|
|
321
|
-
if(error){
|
|
322
|
-
if(config?.debug===true){console.error('H2I:95',error);}
|
|
358
|
+
}, (error, res) => {
|
|
359
|
+
if (error) {
|
|
360
|
+
if (config?.debug === true) { console.error('H2I:95', error); }
|
|
323
361
|
return resolve('');
|
|
324
362
|
}
|
|
325
|
-
if(res?.body){
|
|
326
|
-
try{
|
|
327
|
-
let obj=JSON.parse(res?.body);
|
|
328
|
-
if(obj?.status == 'success' && obj?.url?.length){
|
|
363
|
+
if (res?.body) {
|
|
364
|
+
try {
|
|
365
|
+
let obj = JSON.parse(res?.body);
|
|
366
|
+
if (obj?.status == 'success' && obj?.url?.length) {
|
|
329
367
|
let finalUrl = obj?.url?.replace(/mdh.ezobooks/, 'mdi.ezobooks')?.replace(/md1.ezobooks/, 'mdi.ezobooks');
|
|
330
368
|
return resolve(finalUrl);
|
|
331
369
|
|
|
332
|
-
}else{
|
|
333
|
-
if(config?.debug===true){console.error('H2I:105',obj);}
|
|
370
|
+
} else {
|
|
371
|
+
if (config?.debug === true) { console.error('H2I:105', obj); }
|
|
334
372
|
|
|
335
373
|
return resolve('');
|
|
336
374
|
|
|
337
375
|
}
|
|
338
|
-
}catch(err){
|
|
339
|
-
if(config?.debug===true){console.error('H2I:111',err);}
|
|
340
|
-
|
|
376
|
+
} catch (err) {
|
|
377
|
+
if (config?.debug === true) { console.error('H2I:111', err); }
|
|
378
|
+
|
|
341
379
|
return resolve('');
|
|
342
380
|
|
|
343
381
|
}
|
|
@@ -352,24 +390,24 @@ export class H2I {
|
|
|
352
390
|
|
|
353
391
|
public static getReelVid(config: {
|
|
354
392
|
productVideoUrl: string,
|
|
355
|
-
modelVideoUrl:string,
|
|
356
|
-
infoImageUrl:string,
|
|
357
|
-
requestId:string,
|
|
358
|
-
debug?:boolean
|
|
359
|
-
}):Promise<string> {
|
|
360
|
-
return new Promise(async (resolve)=>{
|
|
361
|
-
let url=await this.getReelTryOnce(config)
|
|
362
|
-
if(url?.length){
|
|
393
|
+
modelVideoUrl: string,
|
|
394
|
+
infoImageUrl: string,
|
|
395
|
+
requestId: string,
|
|
396
|
+
debug?: boolean
|
|
397
|
+
}): Promise<string> {
|
|
398
|
+
return new Promise(async (resolve) => {
|
|
399
|
+
let url = await this.getReelTryOnce(config)
|
|
400
|
+
if (url?.length) {
|
|
363
401
|
return resolve(url);
|
|
364
402
|
}
|
|
365
|
-
let retryMap:{[key:number]:number}={
|
|
366
|
-
50:10, 500:10, 1000:10, 2000:10, 5000:10, 20000:5
|
|
403
|
+
let retryMap: { [key: number]: number } = {
|
|
404
|
+
50: 10, 500: 10, 1000: 10, 2000: 10, 5000: 10, 20000: 5
|
|
367
405
|
}
|
|
368
|
-
for(let k in retryMap){
|
|
369
|
-
for(let i=0;i<Number(retryMap[k]);i++){
|
|
406
|
+
for (let k in retryMap) {
|
|
407
|
+
for (let i = 0; i < Number(retryMap[k]); i++) {
|
|
370
408
|
await Utils.wait(Number(k));
|
|
371
|
-
url=await this.getReelTryOnce(config)
|
|
372
|
-
if(url?.length){
|
|
409
|
+
url = await this.getReelTryOnce(config)
|
|
410
|
+
if (url?.length) {
|
|
373
411
|
return resolve(url);
|
|
374
412
|
}
|
|
375
413
|
}
|
|
@@ -383,43 +421,43 @@ export class H2I {
|
|
|
383
421
|
|
|
384
422
|
public static getReelTryOnce(config: {
|
|
385
423
|
productVideoUrl: string,
|
|
386
|
-
modelVideoUrl:string,
|
|
387
|
-
infoImageUrl:string,
|
|
388
|
-
requestId:string,
|
|
389
|
-
debug?:boolean
|
|
390
|
-
}):Promise<string> {
|
|
391
|
-
return new Promise((resolve)=>{
|
|
424
|
+
modelVideoUrl: string,
|
|
425
|
+
infoImageUrl: string,
|
|
426
|
+
requestId: string,
|
|
427
|
+
debug?: boolean
|
|
428
|
+
}): Promise<string> {
|
|
429
|
+
return new Promise((resolve) => {
|
|
392
430
|
request({
|
|
393
431
|
method: 'POST',
|
|
394
|
-
headers: {'Content-Type': 'application/json'},
|
|
395
|
-
url
|
|
396
|
-
body:JSON.stringify({
|
|
397
|
-
productVideoUrl:config.productVideoUrl,
|
|
398
|
-
modelVideoUrl:config.modelVideoUrl,
|
|
399
|
-
infoImageUrl:config.infoImageUrl,
|
|
400
|
-
requestId:config.requestId,
|
|
432
|
+
headers: { 'Content-Type': 'application/json' },
|
|
433
|
+
url: `https://mdh.ezobooks.in/vd/composeReel`,
|
|
434
|
+
body: JSON.stringify({
|
|
435
|
+
productVideoUrl: config.productVideoUrl,
|
|
436
|
+
modelVideoUrl: config.modelVideoUrl,
|
|
437
|
+
infoImageUrl: config.infoImageUrl,
|
|
438
|
+
requestId: config.requestId,
|
|
401
439
|
})
|
|
402
|
-
},(error,res)=>{
|
|
403
|
-
if(error){
|
|
404
|
-
if(config?.debug===true){console.error('H2I:95',error);}
|
|
440
|
+
}, (error, res) => {
|
|
441
|
+
if (error) {
|
|
442
|
+
if (config?.debug === true) { console.error('H2I:95', error); }
|
|
405
443
|
return resolve('');
|
|
406
444
|
}
|
|
407
|
-
if(res?.body){
|
|
408
|
-
try{
|
|
409
|
-
let obj=JSON.parse(res?.body);
|
|
410
|
-
if(obj?.status == 'success' && obj?.url?.length){
|
|
445
|
+
if (res?.body) {
|
|
446
|
+
try {
|
|
447
|
+
let obj = JSON.parse(res?.body);
|
|
448
|
+
if (obj?.status == 'success' && obj?.url?.length) {
|
|
411
449
|
let finalUrl = obj?.url?.replace(/mdh.ezobooks/, 'mdi.ezobooks')?.replace(/md1.ezobooks/, 'mdi.ezobooks');
|
|
412
450
|
return resolve(finalUrl);
|
|
413
451
|
|
|
414
|
-
}else{
|
|
415
|
-
if(config?.debug===true){console.error('H2I:105',obj);}
|
|
452
|
+
} else {
|
|
453
|
+
if (config?.debug === true) { console.error('H2I:105', obj); }
|
|
416
454
|
|
|
417
455
|
return resolve('');
|
|
418
456
|
|
|
419
457
|
}
|
|
420
|
-
}catch(err){
|
|
421
|
-
if(config?.debug===true){console.error('H2I:111',err);}
|
|
422
|
-
|
|
458
|
+
} catch (err) {
|
|
459
|
+
if (config?.debug === true) { console.error('H2I:111', err); }
|
|
460
|
+
|
|
423
461
|
return resolve('');
|
|
424
462
|
|
|
425
463
|
}
|
|
@@ -431,27 +469,27 @@ export class H2I {
|
|
|
431
469
|
|
|
432
470
|
}
|
|
433
471
|
|
|
434
|
-
|
|
472
|
+
|
|
435
473
|
public static getSceneVid(config: {
|
|
436
|
-
requestId:string,
|
|
474
|
+
requestId: string,
|
|
437
475
|
videos: string[],
|
|
438
|
-
overlayImage:string,
|
|
439
|
-
epilogue:string,
|
|
440
|
-
debug?:boolean
|
|
441
|
-
}):Promise<string> {
|
|
442
|
-
return new Promise(async (resolve)=>{
|
|
443
|
-
let url=await this.getSceneVidTryOnce(config)
|
|
444
|
-
if(url?.length){
|
|
476
|
+
overlayImage: string,
|
|
477
|
+
epilogue: string,
|
|
478
|
+
debug?: boolean
|
|
479
|
+
}): Promise<string> {
|
|
480
|
+
return new Promise(async (resolve) => {
|
|
481
|
+
let url = await this.getSceneVidTryOnce(config)
|
|
482
|
+
if (url?.length) {
|
|
445
483
|
return resolve(url);
|
|
446
484
|
}
|
|
447
|
-
let retryMap:{[key:number]:number}={
|
|
448
|
-
50:10, 500:10, 1000:10, 2000:10, 5000:10, 20000:5
|
|
485
|
+
let retryMap: { [key: number]: number } = {
|
|
486
|
+
50: 10, 500: 10, 1000: 10, 2000: 10, 5000: 10, 20000: 5
|
|
449
487
|
}
|
|
450
|
-
for(let k in retryMap){
|
|
451
|
-
for(let i=0;i<Number(retryMap[k]);i++){
|
|
488
|
+
for (let k in retryMap) {
|
|
489
|
+
for (let i = 0; i < Number(retryMap[k]); i++) {
|
|
452
490
|
await Utils.wait(Number(k));
|
|
453
|
-
url=await this.getSceneVidTryOnce(config)
|
|
454
|
-
if(url?.length){
|
|
491
|
+
url = await this.getSceneVidTryOnce(config)
|
|
492
|
+
if (url?.length) {
|
|
455
493
|
return resolve(url);
|
|
456
494
|
}
|
|
457
495
|
}
|
|
@@ -464,44 +502,44 @@ export class H2I {
|
|
|
464
502
|
}
|
|
465
503
|
|
|
466
504
|
public static getSceneVidTryOnce(config: {
|
|
467
|
-
requestId:string,
|
|
505
|
+
requestId: string,
|
|
468
506
|
videos: string[],
|
|
469
|
-
overlayImage:string,
|
|
470
|
-
epilogue:string,
|
|
471
|
-
debug?:boolean
|
|
472
|
-
}):Promise<string> {
|
|
473
|
-
return new Promise((resolve)=>{
|
|
507
|
+
overlayImage: string,
|
|
508
|
+
epilogue: string,
|
|
509
|
+
debug?: boolean
|
|
510
|
+
}): Promise<string> {
|
|
511
|
+
return new Promise((resolve) => {
|
|
474
512
|
request({
|
|
475
513
|
method: 'POST',
|
|
476
|
-
headers: {'Content-Type': 'application/json'},
|
|
477
|
-
url
|
|
478
|
-
body:JSON.stringify({
|
|
479
|
-
requestId:config.requestId,
|
|
480
|
-
videos:config.videos,
|
|
481
|
-
overlayImage:config.overlayImage,
|
|
482
|
-
epilogue:config.epilogue,
|
|
514
|
+
headers: { 'Content-Type': 'application/json' },
|
|
515
|
+
url: `https://mdh.ezobooks.in/vd/composeScene`,
|
|
516
|
+
body: JSON.stringify({
|
|
517
|
+
requestId: config.requestId,
|
|
518
|
+
videos: config.videos,
|
|
519
|
+
overlayImage: config.overlayImage,
|
|
520
|
+
epilogue: config.epilogue,
|
|
483
521
|
})
|
|
484
|
-
},(error,res)=>{
|
|
485
|
-
if(error){
|
|
486
|
-
if(config?.debug===true){console.error('H2I:95',error);}
|
|
522
|
+
}, (error, res) => {
|
|
523
|
+
if (error) {
|
|
524
|
+
if (config?.debug === true) { console.error('H2I:95', error); }
|
|
487
525
|
return resolve('');
|
|
488
526
|
}
|
|
489
|
-
if(res?.body){
|
|
490
|
-
try{
|
|
491
|
-
let obj=JSON.parse(res?.body);
|
|
492
|
-
if(obj?.status == 'success' && obj?.url?.length){
|
|
527
|
+
if (res?.body) {
|
|
528
|
+
try {
|
|
529
|
+
let obj = JSON.parse(res?.body);
|
|
530
|
+
if (obj?.status == 'success' && obj?.url?.length) {
|
|
493
531
|
let finalUrl = obj?.url?.replace(/mdh.ezobooks/, 'mdi.ezobooks')?.replace(/md1.ezobooks/, 'mdi.ezobooks');
|
|
494
532
|
return resolve(finalUrl);
|
|
495
533
|
|
|
496
|
-
}else{
|
|
497
|
-
if(config?.debug===true){console.error('H2I:105',obj);}
|
|
534
|
+
} else {
|
|
535
|
+
if (config?.debug === true) { console.error('H2I:105', obj); }
|
|
498
536
|
|
|
499
537
|
return resolve('');
|
|
500
538
|
|
|
501
539
|
}
|
|
502
|
-
}catch(err){
|
|
503
|
-
if(config?.debug===true){console.error('H2I:111',err);}
|
|
504
|
-
|
|
540
|
+
} catch (err) {
|
|
541
|
+
if (config?.debug === true) { console.error('H2I:111', err); }
|
|
542
|
+
|
|
505
543
|
return resolve('');
|
|
506
544
|
|
|
507
545
|
}
|
|
@@ -514,26 +552,26 @@ export class H2I {
|
|
|
514
552
|
}
|
|
515
553
|
|
|
516
554
|
public static compileVideoByCommand(config: {
|
|
517
|
-
requestId:string,
|
|
555
|
+
requestId: string,
|
|
518
556
|
ffmpegCommand: string,
|
|
519
557
|
mediaMap: {
|
|
520
|
-
[key:string]:string
|
|
558
|
+
[key: string]: string
|
|
521
559
|
}
|
|
522
|
-
debug?:boolean
|
|
523
|
-
}):Promise<string> {
|
|
524
|
-
return new Promise(async (resolve)=>{
|
|
525
|
-
let url=await this.compileVideoByCommandTryOnce(config)
|
|
526
|
-
if(url?.length){
|
|
560
|
+
debug?: boolean
|
|
561
|
+
}): Promise<string> {
|
|
562
|
+
return new Promise(async (resolve) => {
|
|
563
|
+
let url = await this.compileVideoByCommandTryOnce(config)
|
|
564
|
+
if (url?.length) {
|
|
527
565
|
return resolve(url);
|
|
528
566
|
}
|
|
529
|
-
let retryMap:{[key:number]:number}={
|
|
530
|
-
50:10, 500:10, 1000:10, 2000:10, 5000:10, 20000:5
|
|
567
|
+
let retryMap: { [key: number]: number } = {
|
|
568
|
+
50: 10, 500: 10, 1000: 10, 2000: 10, 5000: 10, 20000: 5
|
|
531
569
|
}
|
|
532
|
-
for(let k in retryMap){
|
|
533
|
-
for(let i=0;i<Number(retryMap[k]);i++){
|
|
570
|
+
for (let k in retryMap) {
|
|
571
|
+
for (let i = 0; i < Number(retryMap[k]); i++) {
|
|
534
572
|
await Utils.wait(Number(k));
|
|
535
|
-
url=await this.compileVideoByCommandTryOnce(config)
|
|
536
|
-
if(url?.length){
|
|
573
|
+
url = await this.compileVideoByCommandTryOnce(config)
|
|
574
|
+
if (url?.length) {
|
|
537
575
|
return resolve(url);
|
|
538
576
|
}
|
|
539
577
|
}
|
|
@@ -546,44 +584,44 @@ export class H2I {
|
|
|
546
584
|
}
|
|
547
585
|
|
|
548
586
|
public static compileVideoByCommandTryOnce(config: {
|
|
549
|
-
requestId:string,
|
|
587
|
+
requestId: string,
|
|
550
588
|
ffmpegCommand: string,
|
|
551
589
|
mediaMap: {
|
|
552
|
-
[key:string]:string
|
|
590
|
+
[key: string]: string
|
|
553
591
|
}
|
|
554
|
-
debug?:boolean
|
|
555
|
-
}):Promise<string> {
|
|
556
|
-
return new Promise((resolve)=>{
|
|
592
|
+
debug?: boolean
|
|
593
|
+
}): Promise<string> {
|
|
594
|
+
return new Promise((resolve) => {
|
|
557
595
|
request({
|
|
558
596
|
method: 'POST',
|
|
559
|
-
headers: {'Content-Type': 'application/json'},
|
|
560
|
-
url
|
|
561
|
-
body:JSON.stringify({
|
|
562
|
-
requestId:config.requestId,
|
|
563
|
-
ffmpegCommand:config.ffmpegCommand,
|
|
564
|
-
mediaMap:config.mediaMap
|
|
597
|
+
headers: { 'Content-Type': 'application/json' },
|
|
598
|
+
url: `https://mdh.ezobooks.in/vd/compileVideoCommand`,
|
|
599
|
+
body: JSON.stringify({
|
|
600
|
+
requestId: config.requestId,
|
|
601
|
+
ffmpegCommand: config.ffmpegCommand,
|
|
602
|
+
mediaMap: config.mediaMap
|
|
565
603
|
})
|
|
566
|
-
},(error,res)=>{
|
|
567
|
-
if(error){
|
|
568
|
-
if(config?.debug===true){console.error('H2I:95',error);}
|
|
604
|
+
}, (error, res) => {
|
|
605
|
+
if (error) {
|
|
606
|
+
if (config?.debug === true) { console.error('H2I:95', error); }
|
|
569
607
|
return resolve('');
|
|
570
608
|
}
|
|
571
|
-
if(res?.body){
|
|
572
|
-
try{
|
|
573
|
-
let obj=JSON.parse(res?.body);
|
|
574
|
-
if(obj?.status == 'success' && obj?.url?.length){
|
|
609
|
+
if (res?.body) {
|
|
610
|
+
try {
|
|
611
|
+
let obj = JSON.parse(res?.body);
|
|
612
|
+
if (obj?.status == 'success' && obj?.url?.length) {
|
|
575
613
|
let finalUrl = obj?.url?.replace(/mdh.ezobooks/, 'mdi.ezobooks')?.replace(/md1.ezobooks/, 'mdi.ezobooks');
|
|
576
614
|
return resolve(finalUrl);
|
|
577
615
|
|
|
578
|
-
}else{
|
|
579
|
-
if(config?.debug===true){console.error('H2I:105',obj);}
|
|
616
|
+
} else {
|
|
617
|
+
if (config?.debug === true) { console.error('H2I:105', obj); }
|
|
580
618
|
|
|
581
619
|
return resolve('');
|
|
582
620
|
|
|
583
621
|
}
|
|
584
|
-
}catch(err){
|
|
585
|
-
if(config?.debug===true){console.error('H2I:111',err);}
|
|
586
|
-
|
|
622
|
+
} catch (err) {
|
|
623
|
+
if (config?.debug === true) { console.error('H2I:111', err); }
|
|
624
|
+
|
|
587
625
|
return resolve('');
|
|
588
626
|
|
|
589
627
|
}
|
|
@@ -597,36 +635,36 @@ export class H2I {
|
|
|
597
635
|
|
|
598
636
|
|
|
599
637
|
public static getVideoByPrompt(config: {
|
|
600
|
-
prompt:string,
|
|
601
|
-
mode:'original'|'fast'
|
|
602
|
-
}):Promise<string> {
|
|
603
|
-
return new Promise((resolve)=>{
|
|
638
|
+
prompt: string,
|
|
639
|
+
mode: 'original' | 'fast'
|
|
640
|
+
}): Promise<string> {
|
|
641
|
+
return new Promise((resolve) => {
|
|
604
642
|
request({
|
|
605
643
|
method: 'POST',
|
|
606
|
-
headers: {'Content-Type': 'application/json'},
|
|
607
|
-
url
|
|
608
|
-
body:JSON.stringify({
|
|
609
|
-
videoPrompt:config.prompt,
|
|
610
|
-
videoModel:config.mode,
|
|
644
|
+
headers: { 'Content-Type': 'application/json' },
|
|
645
|
+
url: `https://mdh.ezobooks.in/vd/aivideo`,
|
|
646
|
+
body: JSON.stringify({
|
|
647
|
+
videoPrompt: config.prompt,
|
|
648
|
+
videoModel: config.mode,
|
|
611
649
|
})
|
|
612
|
-
},(error,res)=>{
|
|
613
|
-
if(error){
|
|
650
|
+
}, (error, res) => {
|
|
651
|
+
if (error) {
|
|
614
652
|
return resolve('');
|
|
615
653
|
}
|
|
616
|
-
if(res?.body){
|
|
617
|
-
try{
|
|
618
|
-
let obj=JSON.parse(res?.body);
|
|
619
|
-
if(obj?.status == 'success' && obj?.vidUrl?.length){
|
|
654
|
+
if (res?.body) {
|
|
655
|
+
try {
|
|
656
|
+
let obj = JSON.parse(res?.body);
|
|
657
|
+
if (obj?.status == 'success' && obj?.vidUrl?.length) {
|
|
620
658
|
let finalUrl = obj?.vidUrl?.replace(/mdh.ezobooks/, 'mdi.ezobooks')?.replace(/md1.ezobooks/, 'mdi.ezobooks');
|
|
621
659
|
return resolve(finalUrl);
|
|
622
660
|
|
|
623
|
-
}else{
|
|
624
|
-
|
|
661
|
+
} else {
|
|
662
|
+
|
|
625
663
|
return resolve('');
|
|
626
664
|
|
|
627
665
|
}
|
|
628
|
-
}catch(err){
|
|
629
|
-
|
|
666
|
+
} catch (err) {
|
|
667
|
+
|
|
630
668
|
return resolve('');
|
|
631
669
|
|
|
632
670
|
}
|