Add matrix-sendfile and matrix-recvfile nodes for JPEG/attachment support #2
Loading…
Reference in a new issue
No description provided.
Delete branch "claude/node-red-contrib-matrix: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?
This is the follow-up requested during the audit: the old pinned matrix-js-sdk v5 (now upgraded in #1) 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 #1).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).(Previously staged as claude/node-red-contrib-matrix#2, stacked on the now-merged #1, while this repo's stale default-branch setting blocked opening it directly against the upstream. Re-opened here now that #1 is merged and that's fixed, so this diff is just the two new nodes.)
Version in package.json auf 0.1.1 angehoben (Attachment-Support), Commit
6d7230eb2cauf feature/matrix-file-attachments.