Add matrix-sendfile and matrix-recvfile nodes for JPEG/attachment support #2
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/matrix-file-attachments"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Stacked on #1 (matrix-js-sdk v42 upgrade) - this needs that base branch's dynamic-import/async-client-init pattern and the v42 SDK's
uploadContent/sendImageMessage/mxcUrlToHttpAPIs, so it's built on top rather than againstmaster.This is the follow-up requested during the audit: the old pinned matrix-js-sdk v5 was blamed for the plugin never supporting attachments (JPEGs etc). Checked the current SDK's types and even v5's own JSDoc -
uploadContent/sendImageMessagehave supported Node.js (Buffer/String/ReadStream) for a long time, so it looks like this was never really an SDK limitation, just a feature the plugin never implemented. Adding it now:matrix-sendfile (function node, 1 input): takes
msg.payload(a Buffer), uploads it viaclient.uploadContent(), then sends it asm.image(viasendImageMessage) whenmsg.mimetypestarts withimage/, or as a genericm.fileevent otherwise.msg.filename/msg.mimetypeare optional (default to"file"/"application/octet-stream"). Room selection mirrors matrix-sendtext:msg.roomId> node's room config > server's default room.matrix-recvfile (function node, 1 output): listens for
m.room.messageevents whosemsgtypeism.image/m.file/m.video/m.audio, resolves themxc://URL viamxcUrlToHttp(..., useAuthentication: true)and downloads it with a BearerAuthorizationheader (current Synapse/Dendrite require authenticated media per MSC3916), emittingmsg.payload(Buffer),msg.filename,msg.mimetype,msg.msgtype,msg.sender,msg.roomId.filterselfand room filtering mirror matrix-recvtext. An encrypted attachment (content carriesfileinstead ofurl) is skipped with a warning, since this module doesn't enable end-to-end encryption (same stated boundary as the SDK-upgrade PR).Testing done: wrote a small local fake HTTP homeserver (plain Node
http) that implements just enough surface - a media upload endpoint, a room-send endpoint, and an authenticated-media-download endpoint that actually rejects requests missing the bearer token - and drove the real, npm-installedmatrix-js-sdk@42.4.0against it directly (upload → content_uri → sendImageMessage/sendEvent → event_id, and mxcUrlToHttp → authenticated fetch → correct bytes back, plus confirming an unauthenticated download is rejected). Then ran a second, full-integration test thatrequire()s this actualmatrix.jsagainst a stub Node-RED runtime, wires a realmatrix-serverconfig node to that fake server, and drivesmatrix-sendfile(image path, generic-file path, and a non-Buffer-payload rejection case) andmatrix-recvfile(successful download producing the right msg fields,filterselfcorrectly dropping our own message, and a plainm.textmessage correctly being ignored) end-to-end through the real node code. All assertions passed.Not tested: against a real Matrix homeserver or inside an actual running Node-RED instance - please verify there before merging, especially the MSC3916 authenticated-media assumption against your actual homeserver version, and larger file uploads (uploadContent's
progressHandler/abortControlleroptions exist but aren't wired up here - happy to add if useful, e.g. for large video files).Update: the repo's stale default-branch setting (pointed at a non-existent "main" ref) has been fixed, and the base PR is now correctly open directly against the upstream repo as jochen/node-red-contrib-matrix#1.
This PR (attachment support) stays open here against
modernize/matrix-js-sdk-42-upgradefor now, since that branch only exists in this fork and cross-repo PR bases must exist in the target repo. Once jochen/node-red-contrib-matrix#1 is merged, I'll open a fresh PR offeature/matrix-file-attachmentsdirectly against jochen/node-red-contrib-matrix master, which will then have a clean, minimal diff (just the two new nodes, not the SDK upgrade too).Superseded by jochen/node-red-contrib-matrix#2, opened directly against master now that #1 is merged and the default-branch bug is fixed - clean diff there (just matrix.js + matrix.html, no SDK-upgrade changes mixed in). Closing this fork-internal duplicate.
Pull request closed