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 <[email protected]>
This commit is contained in:
@@ -1392,6 +1392,29 @@ async function dispatchUiMessage (platform, msg, hooks = {}) {
|
|||||||
})
|
})
|
||||||
return true
|
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') {
|
if (t === 'upsert-guild-emoji') {
|
||||||
await platform.upsertGuildEmoji({
|
await platform.upsertGuildEmoji({
|
||||||
name: msg.name,
|
name: msg.name,
|
||||||
|
|||||||
Reference in New Issue
Block a user