Compare commits

..

2 commits

Author SHA1 Message Date
a66b93ed26 Merged my branches 2026-02-19 16:25:03 +00:00
2c7831c587 Small TypeScript coverage expansion
* The guard() function in m2d/event-dispatcher.js no longer takes (any, any), but a string and a function.

* m2d/send-event.js no longer complains that res.body has some missing fields. It would appear as though those missing fields weren't revelant to the fromWeb() function (into which res.body is passed), given that this code worked before and still contunes to work, so I just @ts-ignore'd res.body

This commit's developer's off-topic personal comment, related to this commit: This has nothing to do with improving thread UX, even tho this is what I was supposed to work on. However, in my attempts to discover in what file should I start, I stumbled upon those errors from m2d/send-event.js, so I fixed them. And after establishing that m2d/event-dispatcher.js is the file that I'm looking for, I also noticed that guard()'s @parm definitions could be improved, so I did that. Now - back to thread work...
2026-02-19 16:19:39 +00:00
2 changed files with 13 additions and 3 deletions

View file

@ -39,14 +39,20 @@ 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"))
await api.getMedia(p.mxc).then(res => stream.Readable.fromWeb(res.body).pipe(d)) await api.getMedia(p.mxc).then(res => stream.Readable.fromWeb(
// @ts-ignore
res.body
).pipe(d))
return { return {
name: p.name, name: p.name,
file: d file: d
} }
} else { } else {
// Unencrypted file // Unencrypted file
const body = await api.getMedia(p.mxc).then(res => stream.Readable.fromWeb(res.body)) const body = await api.getMedia(p.mxc).then(res => stream.Readable.fromWeb(
// @ts-ignore
res.body
))
return { return {
name: p.name, name: p.name,
file: body file: body

View file

@ -156,8 +156,12 @@ async function sendError(roomID, source, type, e, payload) {
} catch (e) {} } catch (e) {}
} }
/**
* @param {string} type
* @param {(event: any, ...args: any)=>any} fn
*/
function guard(type, fn) { function guard(type, fn) {
return async function(event, ...args) { return async function(/** @type {Ty.Event.Outer<any>} */ event, /** @type {any} */ ...args) {
try { try {
return await fn(event, ...args) return await fn(event, ...args)
} catch (e) { } catch (e) {