Honour downloadMedia=true when media download is disabled - #2211
Open
Elimeshi1 wants to merge 1 commit into
Open
Honour downloadMedia=true when media download is disabled#2211Elimeshi1 wants to merge 1 commit into
Elimeshi1 wants to merge 1 commit into
Conversation
With WHATSAPP_DOWNLOAD_MEDIA=false, `mimetypes` becomes a single sentinel
value that matches nothing, so no media is ever downloaded. A request that
explicitly asks for it - GET /api/{session}/chats/{chatId}/messages?downloadMedia=true
- is silently ignored: the response comes back with no media and no
indication that the parameter was dropped.
Thread a `force` flag from the request down to the mimetype check. It
overrides only the global "download disabled" sentinel, never a real
WHATSAPP_FILES_MIMETYPES allow list, so configuring an allow list still
means what it says.
Applied to all four engines, since each defines its own
processIncomingMessage/downloadMedia pair. Internal callers that pass a
literal true/false are untouched - only a user-supplied downloadMedia
forces the download.
The sentinel string is now the exported IGNORE_ALL_MEDIA_MIMETYPE constant
rather than being spelled out in two places.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
With
WHATSAPP_DOWNLOAD_MEDIA=false,WhatsappConfigService.mimetypesreturns a single sentinel value:It matches no real mimetype, so
shouldProcessMimetype()rejects everything — which is the point. But it also means a request that explicitly asks for the media is ignored:The response comes back with no media and no indication that the parameter was dropped.
downloadMediais a documented query parameter, so the caller has no way to tell whether the message had no media or the download was silently skipped.This matters for the setup the flag exists for: media download is turned off because the volume is not worth storing, but occasionally one specific message's media is needed on demand.
The fix
A
forceflag threaded from the request down to the mimetype check:It overrides only the global "download disabled" sentinel, never a real
WHATSAPP_FILES_MIMETYPESallow list — an allow list still means what it says, anddownloadMedia=truecannot smuggle avideo/mp4past a list that permits only images.Applied to all four engines, since each defines its own
processIncomingMessage/downloadMediaSafe/downloadMediatrio rather than inheriting one. Internal callers that pass a literaltrue/falseare left alone: only a user-supplieddownloadMediasetsforce, so nothing changes for event-driven message processing.The sentinel is now the exported
IGNORE_ALL_MEDIA_MIMETYPEconstant instead of being spelled out inconfig.service.tsand compared inMediaManager.ts.Testing
tsc --noEmitandprettierclean.The behaviour has been running in our own deployment with
WHATSAPP_DOWNLOAD_MEDIA=false, wheredownloadMedia=truereturns the media and leaving it unset still returns none. The allow-list path is untouched by construction —forceis only consulted inside the sentinel branch — but I have not exercised it with a realWHATSAPP_FILES_MIMETYPESlist.Extending the same change to WEBJS and WPP is new here; our deployment only runs NOWEB and GOWS.