n8n-nodes-zalo-custom 1.0.10 → 1.1.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/README.md +51 -48
- package/nodes/ZaloGroup/ZaloGroup.node.js +127 -136
- package/nodes/ZaloGroup/ZaloGroupDescription.js +79 -70
- package/nodes/ZaloSendMessage/ZaloSendMessage.node.js +3 -532
- package/nodes/ZaloSendMessage/ZaloSendMessageDescription.js +389 -0
- package/nodes/ZaloUploadAttachment/ZaloUploadAttachment.node.js +24 -26
- package/nodes/ZaloUploadAttachment/ZaloUploadAttachmentDescription.js +1 -1
- package/nodes/ZaloUser/ZaloUser.node.js +95 -1
- package/nodes/ZaloUser/ZaloUserDescription.js +297 -47
- package/nodes/utils/helper.js +148 -0
- package/nodes/utils/zalo.helper.js +12 -6
- package/package.json +1 -1
|
@@ -91,12 +91,6 @@ exports.zaloUserOperations = [
|
|
|
91
91
|
action: 'Lấy QR người dùng',
|
|
92
92
|
description: 'Lấy QR của người dùng',
|
|
93
93
|
},
|
|
94
|
-
{
|
|
95
|
-
name: 'Cập Nhật Thông Tin Tài Khoản',
|
|
96
|
-
value: 'updateProfile',
|
|
97
|
-
action: 'Cập nhật thông tin tài khoản',
|
|
98
|
-
description: 'Cập nhật tên, ngày sinh, giới tính của tài khoản',
|
|
99
|
-
},
|
|
100
94
|
{
|
|
101
95
|
name: 'Bỏ Chặn Người Dùng',
|
|
102
96
|
value: 'unblockUser',
|
|
@@ -109,12 +103,6 @@ exports.zaloUserOperations = [
|
|
|
109
103
|
action: 'Chặn người dùng',
|
|
110
104
|
description: 'Chặn người dùng',
|
|
111
105
|
},
|
|
112
|
-
{
|
|
113
|
-
name: 'Thu Hồi Tin Nhắn',
|
|
114
|
-
value: 'undoMessage',
|
|
115
|
-
action: 'Thu hồi tin nhắn',
|
|
116
|
-
description: 'Thu hồi tin nhắn đã gửi',
|
|
117
|
-
},
|
|
118
106
|
{
|
|
119
107
|
name: 'Đánh Dấu Tin Nhắn Chưa Đọc',
|
|
120
108
|
value: 'addUnreadMark',
|
|
@@ -133,6 +121,24 @@ exports.zaloUserOperations = [
|
|
|
133
121
|
action: 'Lấy trạng thái hoạt động của người dùng',
|
|
134
122
|
description: 'Lấy thời gian hoạt động cuối cùng của một người dùng qua User ID',
|
|
135
123
|
},
|
|
124
|
+
{
|
|
125
|
+
name: 'Tắt Hoặc Bật Thông Báo',
|
|
126
|
+
value: 'setMute',
|
|
127
|
+
action: 'Tắt hoặc bật thông báo',
|
|
128
|
+
description: 'Tắt hoặc bật thông báo cho Người dùng/Nhóm',
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'Xóa Tin Nhắn',
|
|
132
|
+
value: 'deleteMessage',
|
|
133
|
+
action: 'Xóa tin nhắn',
|
|
134
|
+
description: 'Xóa tin nhắn (chỉ mình tôi hoặc mọi người nếu là admin)',
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: 'Thu Hồi Tin Nhắn',
|
|
138
|
+
value: 'undoMessage',
|
|
139
|
+
action: 'Thu hồi tin nhắn',
|
|
140
|
+
description: 'Thu hồi tin nhắn đã gửi',
|
|
141
|
+
},
|
|
136
142
|
{
|
|
137
143
|
name: 'Lấy Thông Tin Tài Khoản',
|
|
138
144
|
value: 'fetchAccountInfo',
|
|
@@ -146,30 +152,34 @@ exports.zaloUserOperations = [
|
|
|
146
152
|
description: 'Lấy ngữ cảnh (context) của phiên làm việc hiện tại',
|
|
147
153
|
},
|
|
148
154
|
{
|
|
149
|
-
name: 'Lấy Tin Nhắn Đến Cũ
|
|
155
|
+
name: 'Lấy Tin Nhắn Đến Cũ Của Tài Khoản',
|
|
150
156
|
value: 'getOldMessages',
|
|
151
157
|
action: 'Lấy tin nhắn đến cũ của tài khoản',
|
|
152
158
|
description: 'Lấy các tin nhắn cũ hơn trong một cuộc trò chuyện',
|
|
153
159
|
},
|
|
160
|
+
{
|
|
161
|
+
name: 'Cập Nhật Thông Tin Tài Khoản',
|
|
162
|
+
value: 'updateProfile',
|
|
163
|
+
action: 'Cập nhật thông tin tài khoản',
|
|
164
|
+
description: 'Cập nhật tên, ngày sinh, giới tính của tài khoản',
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: 'Đổi Avatar Tài Khoản',
|
|
168
|
+
value: 'changeAccountAvatar',
|
|
169
|
+
action: 'Đổi avatar tài khoản',
|
|
170
|
+
description: 'Đổi ảnh đại diện của tài khoản hiện tại',
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
name: 'Cập Nhật Cài Đặt Quyền Riêng Tư',
|
|
174
|
+
value: 'updateSettings',
|
|
175
|
+
action: 'Cập nhật cài đặt quyền riêng tư',
|
|
176
|
+
description: 'Cập nhật các cài đặt quyền riêng tư (ngày sinh, trạng thái online, nguồn kết bạn...)',
|
|
177
|
+
},
|
|
154
178
|
],
|
|
155
179
|
default: 'getUserInfo',
|
|
156
180
|
},
|
|
157
181
|
];
|
|
158
182
|
exports.zaloUserFields = [
|
|
159
|
-
{
|
|
160
|
-
displayName: 'Thread ID',
|
|
161
|
-
name: 'threadId',
|
|
162
|
-
type: 'string',
|
|
163
|
-
required: true,
|
|
164
|
-
displayOptions: {
|
|
165
|
-
show: {
|
|
166
|
-
resource: ['zaloUser'],
|
|
167
|
-
operation: ['undoMessage', 'removeUnreadMark', 'addUnreadMark'],
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
default: '',
|
|
171
|
-
description: 'ID của cuộc trò chuyện (có thể là user ID hoặc group ID)',
|
|
172
|
-
},
|
|
173
183
|
{
|
|
174
184
|
displayName: 'Thread Type',
|
|
175
185
|
name: 'threadType',
|
|
@@ -178,23 +188,37 @@ exports.zaloUserFields = [
|
|
|
178
188
|
displayOptions: {
|
|
179
189
|
show: {
|
|
180
190
|
resource: ['zaloUser'],
|
|
181
|
-
operation: ['removeUnreadMark', 'addUnreadMark', 'undoMessage', 'getOldMessages'],
|
|
191
|
+
operation: ['removeUnreadMark', 'addUnreadMark', 'undoMessage', 'getOldMessages', 'setMute', 'deleteMessage'],
|
|
182
192
|
},
|
|
183
193
|
},
|
|
184
194
|
options: [
|
|
185
195
|
{
|
|
186
196
|
name: 'User',
|
|
187
197
|
value: 0,
|
|
188
|
-
description: '
|
|
198
|
+
description: 'Người dùng',
|
|
189
199
|
},
|
|
190
200
|
{
|
|
191
201
|
name: 'Group',
|
|
192
202
|
value: 1,
|
|
193
|
-
description: '
|
|
203
|
+
description: 'Nhóm',
|
|
194
204
|
},
|
|
195
205
|
],
|
|
196
206
|
default: 0,
|
|
197
|
-
description: 'Loại cuộc trò chuyện
|
|
207
|
+
description: 'Loại cuộc trò chuyện đang tương tác',
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
displayName: 'Thread ID',
|
|
211
|
+
name: 'threadId',
|
|
212
|
+
type: 'string',
|
|
213
|
+
required: true,
|
|
214
|
+
displayOptions: {
|
|
215
|
+
show: {
|
|
216
|
+
resource: ['zaloUser'],
|
|
217
|
+
operation: ['undoMessage', 'removeUnreadMark', 'addUnreadMark', 'setMute', 'deleteMessage'],
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
default: '',
|
|
221
|
+
description: 'ID của cuộc trò chuyện (có thể là user ID hoặc group ID)',
|
|
198
222
|
},
|
|
199
223
|
{
|
|
200
224
|
displayName: 'msgId',
|
|
@@ -204,7 +228,7 @@ exports.zaloUserFields = [
|
|
|
204
228
|
displayOptions: {
|
|
205
229
|
show: {
|
|
206
230
|
resource: ['zaloUser'],
|
|
207
|
-
operation: ['undoMessage'],
|
|
231
|
+
operation: ['undoMessage', 'deleteMessage'],
|
|
208
232
|
},
|
|
209
233
|
},
|
|
210
234
|
default: '',
|
|
@@ -218,7 +242,7 @@ exports.zaloUserFields = [
|
|
|
218
242
|
displayOptions: {
|
|
219
243
|
show: {
|
|
220
244
|
resource: ['zaloUser'],
|
|
221
|
-
operation: ['undoMessage'],
|
|
245
|
+
operation: ['undoMessage', 'deleteMessage'],
|
|
222
246
|
},
|
|
223
247
|
},
|
|
224
248
|
default: '',
|
|
@@ -244,6 +268,7 @@ exports.zaloUserFields = [
|
|
|
244
268
|
'undoFriendRequest',
|
|
245
269
|
'getQR',
|
|
246
270
|
'getLastOnline',
|
|
271
|
+
'deleteMessage',
|
|
247
272
|
],
|
|
248
273
|
},
|
|
249
274
|
},
|
|
@@ -349,6 +374,20 @@ exports.zaloUserFields = [
|
|
|
349
374
|
default: 1,
|
|
350
375
|
description: 'Giới tính',
|
|
351
376
|
},
|
|
377
|
+
{
|
|
378
|
+
displayName: 'URL Ảnh',
|
|
379
|
+
name: 'imageUrl',
|
|
380
|
+
type: 'string',
|
|
381
|
+
required: true,
|
|
382
|
+
default: '',
|
|
383
|
+
displayOptions: {
|
|
384
|
+
show: {
|
|
385
|
+
resource: ['zaloUser'],
|
|
386
|
+
operation: ['changeAccountAvatar'],
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
description: 'URL ảnh (nếu avatar cần ảnh hơn 240x240 rõ nét để tránh bị gỡ)',
|
|
390
|
+
},
|
|
352
391
|
{
|
|
353
392
|
displayName: 'Language',
|
|
354
393
|
name: 'language',
|
|
@@ -377,18 +416,229 @@ exports.zaloUserFields = [
|
|
|
377
416
|
default: '',
|
|
378
417
|
description: 'Số điện thoại cần tìm kiếm',
|
|
379
418
|
},
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
419
|
+
{
|
|
420
|
+
displayName: 'Hành Động',
|
|
421
|
+
name: 'muteAction',
|
|
422
|
+
type: 'options',
|
|
423
|
+
options: [
|
|
424
|
+
{
|
|
425
|
+
name: 'Tắt Thông Báo',
|
|
426
|
+
value: 1,
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
name: 'Bật Thông Báo',
|
|
430
|
+
value: 3,
|
|
431
|
+
},
|
|
432
|
+
],
|
|
433
|
+
default: 1,
|
|
434
|
+
displayOptions: {
|
|
435
|
+
show: {
|
|
436
|
+
resource: ['zaloUser'],
|
|
437
|
+
operation: ['setMute'],
|
|
438
|
+
},
|
|
439
|
+
},
|
|
440
|
+
description: 'Chọn hành động tắt hoặc bật thông báo',
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
displayName: 'Thời Gian Tắt',
|
|
444
|
+
name: 'muteDuration',
|
|
445
|
+
type: 'options',
|
|
446
|
+
options: [
|
|
447
|
+
{
|
|
448
|
+
name: '1 Giờ',
|
|
449
|
+
value: 3600,
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
name: '4 Giờ',
|
|
453
|
+
value: 14400,
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
name: 'Đến 8h Sáng',
|
|
457
|
+
value: 'until8AM',
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
name: 'Vĩnh Viễn',
|
|
461
|
+
value: -1,
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
name: 'Tùy Chỉnh (Phút)',
|
|
465
|
+
value: -2,
|
|
466
|
+
},
|
|
467
|
+
],
|
|
468
|
+
default: -1,
|
|
469
|
+
displayOptions: {
|
|
470
|
+
show: {
|
|
471
|
+
resource: ['zaloUser'],
|
|
472
|
+
operation: ['setMute'],
|
|
473
|
+
muteAction: [1],
|
|
474
|
+
},
|
|
475
|
+
},
|
|
476
|
+
description: 'Thời gian tắt thông báo',
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
displayName: 'Số Phút',
|
|
480
|
+
name: 'customMuteDuration',
|
|
481
|
+
type: 'number',
|
|
482
|
+
default: 5,
|
|
483
|
+
required: true,
|
|
484
|
+
displayOptions: {
|
|
485
|
+
show: {
|
|
486
|
+
resource: ['zaloUser'],
|
|
487
|
+
operation: ['setMute'],
|
|
488
|
+
muteAction: [1],
|
|
489
|
+
muteDuration: [-2],
|
|
490
|
+
},
|
|
491
|
+
},
|
|
492
|
+
description: 'Nhập số phút muốn tắt thông báo',
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
displayName: 'Only Me',
|
|
496
|
+
name: 'onlyMe',
|
|
497
|
+
type: 'boolean',
|
|
498
|
+
default: true,
|
|
499
|
+
displayOptions: {
|
|
500
|
+
show: {
|
|
501
|
+
resource: ['zaloUser'],
|
|
502
|
+
operation: ['deleteMessage'],
|
|
503
|
+
},
|
|
504
|
+
},
|
|
505
|
+
description: 'Bật để xóa tin nhắn ở phía bạn. Tắt để xóa với mọi người (quyền admin)',
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
displayName: 'Cài Đặt Quyền Riêng Tư',
|
|
509
|
+
name: 'updateSettingsOptions',
|
|
510
|
+
type: 'collection',
|
|
511
|
+
placeholder: 'Thêm Cài Đặt',
|
|
512
|
+
default: {},
|
|
513
|
+
displayOptions: {
|
|
514
|
+
show: {
|
|
515
|
+
resource: ['zaloUser'],
|
|
516
|
+
operation: ['updateSettings'],
|
|
517
|
+
},
|
|
518
|
+
},
|
|
519
|
+
options: [
|
|
520
|
+
{
|
|
521
|
+
displayName: 'Hiển Thị Ngày Sinh',
|
|
522
|
+
name: 'view_birthday',
|
|
523
|
+
type: 'options',
|
|
524
|
+
default: 0,
|
|
525
|
+
options: [
|
|
526
|
+
{ name: 'Ẩn', value: 0 },
|
|
527
|
+
{ name: 'Hiện Ngày/Tháng/Năm', value: 1 },
|
|
528
|
+
{ name: 'Hiện Ngày/Tháng', value: 2 },
|
|
529
|
+
],
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
displayName: 'Trạng Thái Online',
|
|
533
|
+
name: 'show_online_status',
|
|
534
|
+
type: 'options',
|
|
535
|
+
default: 1,
|
|
536
|
+
options: [
|
|
537
|
+
{ name: 'Ẩn', value: 0 },
|
|
538
|
+
{ name: 'Hiện', value: 1 },
|
|
539
|
+
],
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
displayName: 'Trạng Thái Đã Xem',
|
|
543
|
+
name: 'display_seen_status',
|
|
544
|
+
type: 'options',
|
|
545
|
+
default: 1,
|
|
546
|
+
options: [
|
|
547
|
+
{ name: 'Ẩn', value: 0 },
|
|
548
|
+
{ name: 'Hiện', value: 1 },
|
|
549
|
+
],
|
|
550
|
+
},
|
|
551
|
+
{
|
|
552
|
+
displayName: 'Nhận Tin Nhắn Từ',
|
|
553
|
+
name: 'receive_message',
|
|
554
|
+
type: 'options',
|
|
555
|
+
default: 1,
|
|
556
|
+
options: [
|
|
557
|
+
{ name: 'Mọi Người', value: 1 },
|
|
558
|
+
{ name: 'Chỉ Bạn Bè', value: 2 },
|
|
559
|
+
],
|
|
560
|
+
},
|
|
561
|
+
{
|
|
562
|
+
displayName: 'Nhận Cuộc Gọi Từ',
|
|
563
|
+
name: 'accept_stranger_call',
|
|
564
|
+
type: 'options',
|
|
565
|
+
default: 3,
|
|
566
|
+
options: [
|
|
567
|
+
{ name: 'Chỉ Bạn Bè', value: 2 },
|
|
568
|
+
{ name: 'Mọi Người', value: 3 },
|
|
569
|
+
{ name: 'Bạn Bè & Người Lạ Từng Liên Hệ', value: 4 },
|
|
570
|
+
],
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
displayName: 'Nguồn Kết Bạn: Số Điện Thoại',
|
|
574
|
+
name: 'add_friend_via_phone',
|
|
575
|
+
type: 'options',
|
|
576
|
+
default: 1,
|
|
577
|
+
options: [
|
|
578
|
+
{ name: 'Tắt', value: 0 },
|
|
579
|
+
{ name: 'Bật', value: 1 },
|
|
580
|
+
],
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
displayName: 'Nguồn Kết Bạn: Mã QR',
|
|
584
|
+
name: 'add_friend_via_qr',
|
|
585
|
+
type: 'options',
|
|
586
|
+
default: 1,
|
|
587
|
+
options: [
|
|
588
|
+
{ name: 'Tắt', value: 0 },
|
|
589
|
+
{ name: 'Bật', value: 1 },
|
|
590
|
+
],
|
|
591
|
+
},
|
|
592
|
+
{
|
|
593
|
+
displayName: 'Nguồn Kết Bạn: Nhóm',
|
|
594
|
+
name: 'add_friend_via_group',
|
|
595
|
+
type: 'options',
|
|
596
|
+
default: 1,
|
|
597
|
+
options: [
|
|
598
|
+
{ name: 'Tắt', value: 0 },
|
|
599
|
+
{ name: 'Bật', value: 1 },
|
|
600
|
+
],
|
|
601
|
+
},
|
|
602
|
+
{
|
|
603
|
+
displayName: 'Nguồn Kết Bạn: Danh Thiếp',
|
|
604
|
+
name: 'add_friend_via_contact',
|
|
605
|
+
type: 'options',
|
|
606
|
+
default: 1,
|
|
607
|
+
options: [
|
|
608
|
+
{ name: 'Tắt', value: 0 },
|
|
609
|
+
{ name: 'Bật', value: 1 },
|
|
610
|
+
],
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
displayName: 'Hiện Trong Gợi Ý Kết Bạn',
|
|
614
|
+
name: 'display_on_recommend_friend',
|
|
615
|
+
type: 'options',
|
|
616
|
+
default: 1,
|
|
617
|
+
options: [
|
|
618
|
+
{ name: 'Tắt', value: 0 },
|
|
619
|
+
{ name: 'Bật', value: 1 },
|
|
620
|
+
],
|
|
621
|
+
},
|
|
622
|
+
{
|
|
623
|
+
displayName: 'Ẩn Trò Chuyện',
|
|
624
|
+
name: 'archivedChatStatus',
|
|
625
|
+
type: 'options',
|
|
626
|
+
default: 1,
|
|
627
|
+
options: [
|
|
628
|
+
{ name: 'Tắt', value: 0 },
|
|
629
|
+
{ name: 'Bật', value: 1 },
|
|
630
|
+
],
|
|
631
|
+
},
|
|
632
|
+
{
|
|
633
|
+
displayName: 'Tin Nhắn Nhanh',
|
|
634
|
+
name: 'quickMessageStatus',
|
|
635
|
+
type: 'options',
|
|
636
|
+
default: 1,
|
|
637
|
+
options: [
|
|
638
|
+
{ name: 'Tắt', value: 0 },
|
|
639
|
+
{ name: 'Bật', value: 1 },
|
|
640
|
+
],
|
|
641
|
+
},
|
|
642
|
+
],
|
|
643
|
+
},
|
|
394
644
|
];
|
package/nodes/utils/helper.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.saveFile = saveFile;
|
|
7
7
|
exports.removeFile = removeFile;
|
|
8
|
+
exports.parseHtmlToStyles = parseHtmlToStyles;
|
|
8
9
|
const axios_1 = __importDefault(require("axios"));
|
|
9
10
|
const fs_1 = __importDefault(require("fs"));
|
|
10
11
|
const os_1 = __importDefault(require("os"));
|
|
@@ -39,3 +40,150 @@ function removeFile(filePath) {
|
|
|
39
40
|
console.error('Lỗi khi xoá file:', error);
|
|
40
41
|
}
|
|
41
42
|
}
|
|
43
|
+
function parseHtmlToStyles(html) {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
let workingHtml = html
|
|
46
|
+
.replace(/"/g, '"')
|
|
47
|
+
.replace(/'/g, "'")
|
|
48
|
+
.replace(/</g, '<')
|
|
49
|
+
.replace(/>/g, '>')
|
|
50
|
+
.replace(/&/g, '&')
|
|
51
|
+
.replace(/ /g, ' ');
|
|
52
|
+
workingHtml = workingHtml.replace(/<a[^>]*href="([^"]*)"[^>]*>(.*?)<\/a>/gi, '$2');
|
|
53
|
+
workingHtml = workingHtml.replace(/<br\s*\/?>/gi, '___BR___');
|
|
54
|
+
workingHtml = workingHtml.replace(/>\s+</g, '><');
|
|
55
|
+
workingHtml = workingHtml.replace(/___BR___/g, '<br>');
|
|
56
|
+
const styles = [];
|
|
57
|
+
const tagMappings = {
|
|
58
|
+
'b': 'b',
|
|
59
|
+
'strong': 'b',
|
|
60
|
+
'i': 'i',
|
|
61
|
+
'em': 'i',
|
|
62
|
+
'u': 'u',
|
|
63
|
+
's': 's',
|
|
64
|
+
'strike': 's',
|
|
65
|
+
'del': 's',
|
|
66
|
+
'small': 'f_13',
|
|
67
|
+
'big': 'f_18',
|
|
68
|
+
'red': 'c_db342e',
|
|
69
|
+
'orange': 'c_f27806',
|
|
70
|
+
'yellow': 'c_f7b503',
|
|
71
|
+
'green': 'c_15a85f',
|
|
72
|
+
};
|
|
73
|
+
const openTags = [];
|
|
74
|
+
let cleanText = '';
|
|
75
|
+
let htmlIndex = 0;
|
|
76
|
+
let textIndex = 0;
|
|
77
|
+
while (htmlIndex < workingHtml.length) {
|
|
78
|
+
const char = workingHtml[htmlIndex];
|
|
79
|
+
if (char === '<') {
|
|
80
|
+
const tagEndIndex = workingHtml.indexOf('>', htmlIndex);
|
|
81
|
+
if (tagEndIndex === -1) {
|
|
82
|
+
cleanText += char;
|
|
83
|
+
textIndex++;
|
|
84
|
+
htmlIndex++;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const tagContent = workingHtml.substring(htmlIndex + 1, tagEndIndex);
|
|
88
|
+
const isClosingTag = tagContent.startsWith('/');
|
|
89
|
+
const tagName = (isClosingTag ? tagContent.substring(1) : tagContent.split(/\s/)[0]).toLowerCase();
|
|
90
|
+
if (tagName === 'br') {
|
|
91
|
+
cleanText += '\n';
|
|
92
|
+
textIndex++;
|
|
93
|
+
}
|
|
94
|
+
else if (tagName === 'p') {
|
|
95
|
+
if (isClosingTag) {
|
|
96
|
+
cleanText += '\n\n';
|
|
97
|
+
textIndex += 2;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (tagName === 'div') {
|
|
101
|
+
if (isClosingTag) {
|
|
102
|
+
cleanText += '\n';
|
|
103
|
+
textIndex++;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else if (tagName.match(/^h[1-6]$/)) {
|
|
107
|
+
if (isClosingTag) {
|
|
108
|
+
cleanText += '\n';
|
|
109
|
+
textIndex++;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (tagName === 'li') {
|
|
113
|
+
if (!isClosingTag) {
|
|
114
|
+
cleanText += '• ';
|
|
115
|
+
textIndex += 2;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
cleanText += '\n';
|
|
119
|
+
textIndex++;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else if (tagName === 'ul' || tagName === 'ol') {
|
|
123
|
+
if (!isClosingTag) {
|
|
124
|
+
cleanText += '\n';
|
|
125
|
+
textIndex++;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
cleanText += '\n';
|
|
129
|
+
textIndex++;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const styleType = tagMappings[tagName];
|
|
134
|
+
if (styleType) {
|
|
135
|
+
if (isClosingTag) {
|
|
136
|
+
for (let i = openTags.length - 1; i >= 0; i--) {
|
|
137
|
+
if (openTags[i].tagName === tagName) {
|
|
138
|
+
const openTag = openTags[i];
|
|
139
|
+
if (textIndex > openTag.startPos) {
|
|
140
|
+
styles.push({
|
|
141
|
+
st: openTag.styleType,
|
|
142
|
+
start: openTag.startPos,
|
|
143
|
+
end: textIndex
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
openTags.splice(i, 1);
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
openTags.push({
|
|
153
|
+
tagName: tagName,
|
|
154
|
+
styleType: styleType,
|
|
155
|
+
startPos: textIndex
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
htmlIndex = tagEndIndex + 1;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
cleanText += char;
|
|
164
|
+
textIndex++;
|
|
165
|
+
htmlIndex++;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
for (const openTag of openTags) {
|
|
169
|
+
if (textIndex > openTag.startPos) {
|
|
170
|
+
styles.push({
|
|
171
|
+
st: openTag.styleType,
|
|
172
|
+
start: openTag.startPos,
|
|
173
|
+
end: textIndex
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
cleanText = cleanText
|
|
178
|
+
.replace(/\n\s*\n\s*\n/g, '\n\n')
|
|
179
|
+
.replace(/[ \t]+/g, ' ');
|
|
180
|
+
const trimStart = ((_b = (_a = cleanText.match(/^\s*/)) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.length) || 0;
|
|
181
|
+
cleanText = cleanText.replace(/^\s+|\s+$/g, '');
|
|
182
|
+
if (trimStart > 0) {
|
|
183
|
+
for (const style of styles) {
|
|
184
|
+
style.start = Math.max(0, style.start - trimStart);
|
|
185
|
+
style.end = Math.max(style.start, style.end - trimStart);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return { cleanText, styles };
|
|
189
|
+
}
|
|
@@ -67,12 +67,17 @@ async function persistDb() {
|
|
|
67
67
|
async function imageMetadataGetter(filePath) {
|
|
68
68
|
try {
|
|
69
69
|
const stats = await fs_1.promises.stat(filePath);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
try {
|
|
71
|
+
const dimensions = (0, image_size_1.default)(filePath);
|
|
72
|
+
return {
|
|
73
|
+
height: dimensions.height,
|
|
74
|
+
width: dimensions.width,
|
|
75
|
+
size: stats.size,
|
|
76
|
+
};
|
|
77
|
+
} catch (err) {
|
|
78
|
+
// Nếu không phải ảnh (ví dụ mp4), trả về size thực tế để API xử lý tiếp
|
|
79
|
+
return { height: 0, width: 0, size: stats.size };
|
|
80
|
+
}
|
|
76
81
|
}
|
|
77
82
|
catch (e) {
|
|
78
83
|
if (e.code === 'ENOENT' || e.code === 'EACCES') {
|
|
@@ -81,6 +86,7 @@ async function imageMetadataGetter(filePath) {
|
|
|
81
86
|
else {
|
|
82
87
|
console.log(`Could not get metadata for file at path: ${filePath}. It might not be a valid image file. Error: ${e.message}`);
|
|
83
88
|
}
|
|
89
|
+
return { height: 0, width: 0, size: 0 };
|
|
84
90
|
}
|
|
85
91
|
}
|
|
86
92
|
exports.imageMetadataGetter = imageMetadataGetter;
|
package/package.json
CHANGED