@chat21/chat21-web-widget 5.0.84-rc.3 → 5.0.84-rc.4
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/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
### **Copyrigth**:
|
|
7
7
|
*Tiledesk SRL*
|
|
8
8
|
|
|
9
|
+
# 5.0.84-rc.4
|
|
10
|
+
- **added**: checkAcceptedFile fn on dragleave event conversation-content component
|
|
11
|
+
- **added**: checkAcceptedFile fn in conversation-footer component
|
|
12
|
+
|
|
9
13
|
# 5.0.84-rc.3
|
|
10
14
|
- **changed**: index-dev lib order import
|
|
11
15
|
|
package/package.json
CHANGED
|
@@ -39,6 +39,7 @@ import { CustomTranslateService } from 'src/chat21-core/providers/custom-transla
|
|
|
39
39
|
import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
|
|
40
40
|
import { TiledeskRequestsService } from 'src/chat21-core/providers/tiledesk/tiledesk-requests.service';
|
|
41
41
|
import { ConversationContentComponent } from '../conversation-content/conversation-content.component';
|
|
42
|
+
import { checkAcceptedFile } from 'src/app/utils/utils';
|
|
42
43
|
// import { TranslateService } from '@ngx-translate/core';
|
|
43
44
|
|
|
44
45
|
@Component({
|
|
@@ -1346,34 +1347,32 @@ export class ConversationComponent implements OnInit, AfterViewInit, OnChanges {
|
|
|
1346
1347
|
var mimeType = fileList[0].type
|
|
1347
1348
|
this.logger.log('[CONV-COMP] ----> FILE - DROP mimeType files ', mimeType)
|
|
1348
1349
|
|
|
1349
|
-
// if (mimeType.startsWith("image") || mimeType.startsWith("application")) {
|
|
1350
|
-
// this.logger.log('[CONV-COMP] ----> FILE - DROP mimeType files: ', this.appConfigProvider.getConfig().fileUploadAccept);
|
|
1351
|
-
// this.checkAcceptedFile(mimeType);
|
|
1352
|
-
// const isAccepted = this.checkAcceptedFile(mimeType)
|
|
1353
|
-
// this.logger.log('[CONV-COMP] > checkAcceptedFile - fileUploadAccept isAcceptFile FILE - DROP',isAccepted)
|
|
1354
|
-
// if (isAccepted === true) {
|
|
1355
1350
|
this.dropEvent = event
|
|
1356
|
-
// } else {
|
|
1357
|
-
// this.logger.log( '[CONV-COMP] ----> FILE - DROP mimeType files ', mimeType,'NOT SUPPORTED FILE TYPE')
|
|
1358
|
-
// this.presentToast(this.translationsMap.get('FAILED_TO_UPLOAD_THE_FORMAT_IS_NOT_SUPPORTED'), 'danger','toast-custom-class', 5000 )
|
|
1359
|
-
// // this.presentToastOnlyImageFilesAreAllowedToDrag()
|
|
1360
|
-
// }
|
|
1361
1351
|
|
|
1362
1352
|
}
|
|
1363
1353
|
}
|
|
1364
1354
|
|
|
1365
1355
|
allowDrop(event: any) {
|
|
1366
|
-
event.preventDefault()
|
|
1367
|
-
event.stopPropagation()
|
|
1356
|
+
event.preventDefault();
|
|
1357
|
+
event.stopPropagation();
|
|
1368
1358
|
this.logger.log('[CONV-COMP] ----> FILE - (dragover) allowDrop ev ', event)
|
|
1369
1359
|
this.isHovering = true
|
|
1370
1360
|
}
|
|
1371
1361
|
|
|
1372
1362
|
drag(event){
|
|
1373
|
-
event.preventDefault()
|
|
1363
|
+
event.preventDefault();
|
|
1364
|
+
this.logger.log('[CONV-COMP] ----> FILE - (dragleave) drag ev ', event)
|
|
1365
|
+
if (event.dataTransfer && event.dataTransfer.files) {
|
|
1366
|
+
const files = event.dataTransfer.files;
|
|
1367
|
+
const canUploadFile = checkAcceptedFile(files[0].type, this.appConfigService.getConfig().fileUploadAccept)
|
|
1368
|
+
if(!canUploadFile){
|
|
1369
|
+
this.logger.error('[IMAGE-UPLOAD] detectFiles: can not upload current file type--> NOT ALLOWED', this.appConfigService.getConfig().fileUploadAccept)
|
|
1370
|
+
return;
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1374
1373
|
event.stopPropagation()
|
|
1375
|
-
console.log('dragleave-->', event)
|
|
1376
1374
|
this.isHovering = false
|
|
1377
1375
|
}
|
|
1378
1376
|
|
|
1379
1377
|
}
|
|
1378
|
+
|
package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Component, ComponentFactoryResolver, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild, ViewContainerRef } from '@angular/core';
|
|
2
2
|
import { Globals } from 'src/app/utils/globals';
|
|
3
|
+
import { checkAcceptedFile } from 'src/app/utils/utils';
|
|
3
4
|
import { MessageModel } from 'src/chat21-core/models/message';
|
|
4
5
|
import { UploadModel } from 'src/chat21-core/models/upload';
|
|
5
6
|
import { ConversationHandlerService } from 'src/chat21-core/providers/abstract/conversation-handler.service';
|
|
@@ -130,48 +131,56 @@ export class ConversationFooterComponent implements OnInit, OnChanges {
|
|
|
130
131
|
|
|
131
132
|
const that = this;
|
|
132
133
|
if (event.target.files && event.target.files[0]) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
that.logger.log('[CONV-FOOTER] onload file');
|
|
158
|
-
const fileXLoad = {
|
|
159
|
-
src: reader.result.toString(),
|
|
160
|
-
title: nameFile
|
|
161
|
-
};
|
|
134
|
+
|
|
135
|
+
const canUploadFile = checkAcceptedFile(event.target.files[0].type, this.fileUploadAccept)
|
|
136
|
+
if(!canUploadFile){
|
|
137
|
+
this.logger.error('[IMAGE-UPLOAD] detectFiles: can not upload current file type--> NOT ALLOWED', this.fileUploadAccept)
|
|
138
|
+
this.isFilePendingToUpload = false;
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const nameFile = event.target.files[0].name;
|
|
143
|
+
const typeFile = event.target.files[0].type;
|
|
144
|
+
const size = event.target.files[0].size
|
|
145
|
+
const reader = new FileReader();
|
|
146
|
+
that.logger.debug('[CONV-FOOTER] OK preload: ', nameFile, typeFile, reader);
|
|
147
|
+
reader.addEventListener('load', function () {
|
|
148
|
+
that.logger.debug('[CONV-FOOTER] addEventListener load', reader.result);
|
|
149
|
+
that.isFileSelected = true;
|
|
150
|
+
// se inizia con image
|
|
151
|
+
if (typeFile.startsWith('image') && !typeFile.includes('svg')) {
|
|
152
|
+
const imageXLoad = new Image;
|
|
153
|
+
that.logger.debug('[CONV-FOOTER] onload ', imageXLoad);
|
|
154
|
+
imageXLoad.src = reader.result.toString();
|
|
155
|
+
imageXLoad.title = nameFile;
|
|
156
|
+
imageXLoad.onload = function () {
|
|
157
|
+
that.logger.debug('[CONV-FOOTER] onload image');
|
|
162
158
|
// that.arrayFilesLoad.push(imageXLoad);
|
|
163
159
|
const uid = (new Date().getTime()).toString(36); // imageXLoad.src.substring(imageXLoad.src.length - 16);
|
|
164
|
-
that.arrayFilesLoad[0] = { uid: uid, file:
|
|
165
|
-
that.logger.
|
|
160
|
+
that.arrayFilesLoad[0] = { uid: uid, file: imageXLoad, type: typeFile, size: size };
|
|
161
|
+
that.logger.debug('[CONV-FOOTER] OK: ', that.arrayFilesLoad[0]);
|
|
166
162
|
// SEND MESSAGE
|
|
167
163
|
that.loadFile();
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
164
|
+
};
|
|
165
|
+
} else {
|
|
166
|
+
that.logger.debug('[CONV-FOOTER] onload file');
|
|
167
|
+
const fileXLoad = {
|
|
168
|
+
src: reader.result.toString(),
|
|
169
|
+
title: nameFile
|
|
170
|
+
};
|
|
171
|
+
// that.arrayFilesLoad.push(imageXLoad);
|
|
172
|
+
const uid = (new Date().getTime()).toString(36); // imageXLoad.src.substring(imageXLoad.src.length - 16);
|
|
173
|
+
that.arrayFilesLoad[0] = { uid: uid, file: fileXLoad, type: typeFile, size: size };
|
|
174
|
+
that.logger.debug('[CONV-FOOTER] OK: ', that.arrayFilesLoad[0]);
|
|
175
|
+
// SEND MESSAGE
|
|
176
|
+
that.loadFile();
|
|
174
177
|
}
|
|
178
|
+
}, false);
|
|
179
|
+
|
|
180
|
+
if (event.target.files[0]) {
|
|
181
|
+
reader.readAsDataURL(event.target.files[0]);
|
|
182
|
+
that.logger.debug('[CONV-FOOTER] reader-result: ', event.target.files[0]);
|
|
183
|
+
}
|
|
175
184
|
}
|
|
176
185
|
}
|
|
177
186
|
}
|
package/src/app/utils/utils.ts
CHANGED
|
@@ -387,3 +387,47 @@ export function getUnique(arr, comp) {
|
|
|
387
387
|
// eliminate the dead keys & store unique objects
|
|
388
388
|
.filter(e => arr[e]).map(e => arr[e]);
|
|
389
389
|
}
|
|
390
|
+
|
|
391
|
+
export function checkAcceptedFile(fileType, fileUploadAccept ): boolean{
|
|
392
|
+
|
|
393
|
+
if (fileUploadAccept === '*/*') {
|
|
394
|
+
return true
|
|
395
|
+
}
|
|
396
|
+
// Dividi la stringa fileUploadAccept in un array di tipi accettati
|
|
397
|
+
const acceptedTypes = fileUploadAccept.split(',');
|
|
398
|
+
|
|
399
|
+
// Verifica se il tipo di file è accettato
|
|
400
|
+
return acceptedTypes.some((accept) => {
|
|
401
|
+
accept = accept.trim();
|
|
402
|
+
// Controlla per i tipi MIME con wildcard, come image/*
|
|
403
|
+
if (accept.endsWith('/*')) {
|
|
404
|
+
const baseMimeType = fileType.split('/')[0]; // Ottieni la parte principale del MIME type
|
|
405
|
+
return accept.replace('/*', '') === baseMimeType;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// Controlla se l'accettazione è un MIME type esatto (come image/jpeg)
|
|
409
|
+
if (accept === fileType) {
|
|
410
|
+
return true;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// Controlla per le estensioni di file specifiche come .pdf o .txt
|
|
414
|
+
return fileType === getMimeTypeFromExtension(accept);
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function getMimeTypeFromExtension(extension: string): string {
|
|
420
|
+
// Rimuovi il punto dall'estensione e ottieni il MIME type
|
|
421
|
+
const mimeTypes: { [key: string]: string } = {
|
|
422
|
+
'.jpg': 'image/jpeg',
|
|
423
|
+
'.jpeg': 'image/jpeg',
|
|
424
|
+
'.png': 'image/png',
|
|
425
|
+
'.gif': 'image/gif',
|
|
426
|
+
'.pdf': 'application/pdf',
|
|
427
|
+
'.txt': 'text/plain',
|
|
428
|
+
'.doc': 'application/msword',
|
|
429
|
+
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
430
|
+
// Aggiungi altri tipi MIME se necessario
|
|
431
|
+
};
|
|
432
|
+
return mimeTypes[extension] || '';
|
|
433
|
+
}
|