From fe8647d58e3ebfc36a522c67a8319479732c6c0c Mon Sep 17 00:00:00 2001 From: Gabriele Panico Date: Fri, 24 May 2024 15:32:16 +0200 Subject: [PATCH] added: downloadURL in metadata obj while sending message from tiledesk --- .../conversation-footer.component.ts | 9 +++++---- .../conversation-preview.component.ts | 6 +++--- src/chat21-core/providers/abstract/upload.service.ts | 2 +- .../providers/firebase/firebase-upload.service.ts | 7 ++++--- .../providers/native/native-upload-service.ts | 12 +++++------- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.ts b/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.ts index 14c76dcc..6a7211ed 100644 --- a/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.ts +++ b/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.ts @@ -251,11 +251,12 @@ export class ConversationFooterComponent implements OnInit, OnChanges { // }); // this.resetLoadImage(); - this.uploadService.upload(this.senderId, currentUpload).then(downloadURL => { - that.logger.debug('[CONV-FOOTER] AppComponent::uploadSingle:: downloadURL', downloadURL); - that.logger.debug(`[CONV-FOOTER] Successfully uploaded file and got download link - ${downloadURL}`); + this.uploadService.upload(this.senderId, currentUpload).then(data => { + that.logger.debug('[CONV-FOOTER] AppComponent::uploadSingle:: downloadURL', data); + that.logger.debug(`[CONV-FOOTER] Successfully uploaded file and got download link - ${data}`); - metadata.src = downloadURL; + metadata.src = data.src; + metadata.downloadURL = data.downloadURL; let type_message = TYPE_MSG_TEXT; // let message = 'File: ' + metadata.src; let message = `[${metadata.name}](${metadata.src})` diff --git a/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.ts b/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.ts index 223773b2..8c934c21 100644 --- a/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.ts +++ b/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.ts @@ -153,8 +153,8 @@ export class ConversationPreviewComponent implements OnInit { const metadata = { 'name': imageXLoad.title, 'src': that.sanitizer.bypassSecurityTrustUrl(imageXLoad.src), - 'width': '80px', - 'height': '106px', + 'width': '80', + 'height': '106', 'type': attachment.metadata.type, 'uid': attachment.metadata.uid }; @@ -164,7 +164,7 @@ export class ConversationPreviewComponent implements OnInit { if (!that.fileSelected) { that.fileSelected = Object.assign({}, metadata) // that.fileSelected = Object.assign(that.fileSelected, that.getMetadataSize(that.fileSelected)) - that.sizeImage = that.getMetadataSize(that.fileSelected) + that.sizeImage = that.getMetadataSize(that.fileSelected); } }; } diff --git a/src/chat21-core/providers/abstract/upload.service.ts b/src/chat21-core/providers/abstract/upload.service.ts index 39ef8fd2..8b5c220c 100644 --- a/src/chat21-core/providers/abstract/upload.service.ts +++ b/src/chat21-core/providers/abstract/upload.service.ts @@ -28,7 +28,7 @@ export abstract class UploadService { // functions abstract initialize(): void; - abstract upload(userId: string, upload: UploadModel): Promise; + abstract upload(userId: string, upload: UploadModel): Promise<{downloadURL: string, src: string}>; abstract uploadProfile(userId: string, upload: UploadModel): Promise; abstract delete(userId: string, path: string): Promise; abstract deleteProfile(userId: string, path: string): Promise diff --git a/src/chat21-core/providers/firebase/firebase-upload.service.ts b/src/chat21-core/providers/firebase/firebase-upload.service.ts index 76b97cea..7c00fe22 100644 --- a/src/chat21-core/providers/firebase/firebase-upload.service.ts +++ b/src/chat21-core/providers/firebase/firebase-upload.service.ts @@ -48,7 +48,7 @@ export class FirebaseUploadService extends UploadService { }); } - public upload(userId: string, upload: UploadModel): Promise { + public upload(userId: string, upload: UploadModel): Promise<{downloadURL: string, src: string}> { const that = this; const uid = this.createGuid(); const urlImagesNodeFirebase = '/public/images/' + userId + '/' + uid + '/' + upload.file.name; @@ -93,11 +93,12 @@ export class FirebaseUploadService extends UploadService { }, function error(error) { // Handle unsuccessful uploads reject(error) - }, function complete() { + }, async function complete() { // Handle successful uploads on complete that.logger.debug('[FIREBASEUploadSERVICE] Upload is complete', upload); - resolve(uploadTask.snapshot.ref.getDownloadURL()) + const downloadURL = await uploadTask.snapshot.ref.getDownloadURL(); + resolve({downloadURL : downloadURL, src: downloadURL}) // that.BSStateUpload.next({upload: upload}); }); diff --git a/src/chat21-core/providers/native/native-upload-service.ts b/src/chat21-core/providers/native/native-upload-service.ts index 417fd61d..6aa90591 100644 --- a/src/chat21-core/providers/native/native-upload-service.ts +++ b/src/chat21-core/providers/native/native-upload-service.ts @@ -33,7 +33,7 @@ export class NativeUploadService extends UploadService { } - upload(userId: string, upload: UploadModel): Promise { + upload(userId: string, upload: UploadModel): Promise<{downloadURL: string, src: string}> { this.logger.debug('[NATIVE UPLOAD] - upload new image/file ... upload', upload) const headers = new HttpHeaders({ Authorization: this.tiledeskToken, @@ -51,7 +51,7 @@ export class NativeUploadService extends UploadService { return new Promise((resolve, reject) => { that.http.post(url, formData, requestOptions).subscribe(data => { const downloadURL = this.URL_TILEDESK_IMAGES + '?path=' + data['filename']; - resolve(downloadURL) + resolve({downloadURL : downloadURL, src: downloadURL}) // that.BSStateUpload.next({upload: upload}); }, (error) => { reject(error) @@ -63,11 +63,9 @@ export class NativeUploadService extends UploadService { const url = this.URL_TILEDESK_FILE + '/users' return new Promise((resolve, reject) => { that.http.post(url, formData, requestOptions).subscribe(data => { - let downloadURL = this.URL_TILEDESK_FILE + '/download' + '?path=' + encodeURI(data['filename']); - if(upload.file.type.includes('pdf')){ - downloadURL = this.URL_TILEDESK_FILE + '?path=' + encodeURI(data['filename']); - } - resolve(downloadURL) + const src = this.URL_TILEDESK_FILE + '?path=' + encodeURI(data['filename']); + const downloadURL = this.URL_TILEDESK_FILE + '/download' + '?path=' + encodeURI(data['filename']); + resolve({downloadURL : downloadURL, src: src}) // that.BSStateUpload.next({upload: upload}); }, (error) => { this.logger.error('[NATIVE UPLOAD] - ERROR upload new file ', error)