Skip to content

Commit

Permalink
Merge pull request #336 from jaison-x/adjust-filename-chatwoot
Browse files Browse the repository at this point in the history
perf(chatwoot): only use a axios request to get file mimetype if necessary
  • Loading branch information
DavidsonGomes authored Dec 29, 2023
2 parents af94a0e + d909550 commit 181768d
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/whatsapp/services/chatwoot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,17 +893,21 @@ export class ChatwootService {

try {
this.logger.verbose('get media type');
const parts = media.split('/');
const parsedMedia = path.parse(decodeURIComponent(media));
let mimeType = mimeTypes.lookup(parsedMedia?.ext) || '';
let fileName = parsedMedia?.name + parsedMedia?.ext;

const fileName = decodeURIComponent(parts[parts.length - 1]);
this.logger.verbose('file name: ' + fileName);
if (!mimeType) {
const parts = media.split('/');
fileName = decodeURIComponent(parts[parts.length - 1]);
this.logger.verbose('file name: ' + fileName);

const response = await axios.get(media, {
responseType: 'arraybuffer',
});

const mimeType = response.headers['content-type'];
this.logger.verbose('mime type: ' + mimeType);
const response = await axios.get(media, {
responseType: 'arraybuffer',
});
mimeType = response.headers['content-type'];
this.logger.verbose('mime type: ' + mimeType);
}

let type = 'document';

Expand Down

0 comments on commit 181768d

Please sign in to comment.