Fix m->d encrypted files
This commit is contained in:
@@ -21,7 +21,7 @@ const Rlottie = (async () => {
|
||||
|
||||
/**
|
||||
* @param {string} text
|
||||
* @returns {Promise<import("stream").Readable>}
|
||||
* @returns {Promise<NodeJS.ReadableStream>}
|
||||
*/
|
||||
async function convert(text) {
|
||||
const r = await Rlottie
|
||||
|
@@ -37,16 +37,15 @@ async function resolvePendingFiles(message) {
|
||||
if ("key" in p) {
|
||||
// Encrypted file
|
||||
const d = crypto.createDecipheriv("aes-256-ctr", Buffer.from(p.key, "base64url"), Buffer.from(p.iv, "base64url"))
|
||||
// @ts-ignore
|
||||
await api.getMedia(p.mxc).then(res => res.body.pipe(d))
|
||||
await api.getMedia(p.mxc).then(res => Readable.fromWeb(res.body).pipe(d))
|
||||
return {
|
||||
name: p.name,
|
||||
file: d
|
||||
}
|
||||
} else {
|
||||
// Unencrypted file
|
||||
/** @type {Readable} */ // @ts-ignore
|
||||
const body = await api.getMedia(p.mxc).then(res => res.body)
|
||||
/** @type {Readable} */
|
||||
const body = await api.getMedia(p.mxc).then(res => Readable.fromWeb(res.body))
|
||||
return {
|
||||
name: p.name,
|
||||
file: body
|
||||
|
@@ -343,16 +343,20 @@ async function ping() {
|
||||
/**
|
||||
* @param {string} mxc
|
||||
* @param {RequestInit} [init]
|
||||
* @return {Promise<Response & {body: import("stream/web").ReadableStream<Uint8Array>}>}
|
||||
*/
|
||||
function getMedia(mxc, init = {}) {
|
||||
async function getMedia(mxc, init = {}) {
|
||||
const mediaParts = mxc?.match(/^mxc:\/\/([^/]+)\/(\w+)$/)
|
||||
assert(mediaParts)
|
||||
return fetch(`${mreq.baseUrl}/client/v1/media/download/${mediaParts[1]}/${mediaParts[2]}`, {
|
||||
const res = await fetch(`${mreq.baseUrl}/client/v1/media/download/${mediaParts[1]}/${mediaParts[2]}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${reg.as_token}`
|
||||
},
|
||||
...init
|
||||
})
|
||||
assert(res.body)
|
||||
// @ts-ignore
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user