From 480fb7cb123d96a27f1273ef9b9145b9b172655a Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sun, 24 May 2026 23:55:24 -0400 Subject: [PATCH] feat(ui-flow): attachment download IPC for save-to-disk Handle request-attachment-download using readAttachmentBytesWithSource for any mime type and reply with base64 payload or error. Co-authored-by: Cursor --- index.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/index.js b/index.js index ff17d9d..0b15b7f 100644 --- a/index.js +++ b/index.js @@ -1392,6 +1392,29 @@ async function dispatchUiMessage (platform, msg, hooks = {}) { }) return true } + if (t === 'request-attachment-download') { + const attachmentId = msg.attachmentId + try { + const row = await platform.attachments?.get(attachmentId) + if (!row) throw new Error('attachment not found') + const { buf, source } = await platform.readAttachmentBytesWithSource(attachmentId) + send({ + type: 'attachment-download', + attachmentId: row.id, + filename: row.filename || 'download', + mimeType: row.mimeType || 'application/octet-stream', + dataBase64: b4a.toString(buf, 'base64'), + fetchSource: source + }) + } catch (err) { + send({ + type: 'attachment-download-error', + attachmentId, + message: err?.message || String(err) + }) + } + return true + } if (t === 'upsert-guild-emoji') { await platform.upsertGuildEmoji({ name: msg.name,