Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(chatwoot): only use a axios request to get file mimetype if necessary #336

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/whatsapp/services/chatwoot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,17 +916,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