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