Skip to content

Commit

Permalink
added: downloadURL in metadata obj while sending message from tiledesk
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriele Panico committed May 24, 2024
1 parent 54dd459 commit fe8647d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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})`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand All @@ -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);
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/chat21-core/providers/abstract/upload.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export abstract class UploadService {

// functions
abstract initialize(): void;
abstract upload(userId: string, upload: UploadModel): Promise<any>;
abstract upload(userId: string, upload: UploadModel): Promise<{downloadURL: string, src: string}>;
abstract uploadProfile(userId: string, upload: UploadModel): Promise<any>;
abstract delete(userId: string, path: string): Promise<any>;
abstract deleteProfile(userId: string, path: string): Promise<any>
Expand Down
7 changes: 4 additions & 3 deletions src/chat21-core/providers/firebase/firebase-upload.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class FirebaseUploadService extends UploadService {
});
}

public upload(userId: string, upload: UploadModel): Promise<any> {
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;
Expand Down Expand Up @@ -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});

});
Expand Down
12 changes: 5 additions & 7 deletions src/chat21-core/providers/native/native-upload-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class NativeUploadService extends UploadService {
}


upload(userId: string, upload: UploadModel): Promise<any> {
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,
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit fe8647d

Please sign in to comment.