1
0
Fork 0

add tests, implement kstate and state diffing

This commit is contained in:
Cadence Ember 2023-05-05 17:29:08 +12:00
parent c7868e9dbb
commit f09eeccef3
10 changed files with 2656 additions and 64 deletions

View file

@ -1,6 +1,6 @@
// @ts-check
const fetch = require("node-fetch")
const fetch = require("node-fetch").default
const passthrough = require("../passthrough")
const { sync, db } = passthrough
@ -33,7 +33,6 @@ async function uploadDiscordFileToMxc(path) {
// Download from Discord
const promise = fetch(url, {}).then(/** @param {import("node-fetch").Response} res */ async res => {
/** @ts-ignore @type {import("stream").Readable} body */
const body = res.body
// Upload to Matrix
@ -56,7 +55,7 @@ async function uploadDiscordFileToMxc(path) {
}
function guildIcon(guild) {
return `/icons/${guild.id}/${guild.icon}?size=${IMAGE_SIZE}`
return `/icons/${guild.id}/${guild.icon}.png?size=${IMAGE_SIZE}`
}
module.exports.guildIcon = guildIcon

View file

@ -1,6 +1,6 @@
// @ts-check
const fetch = require("node-fetch")
const fetch = require("node-fetch").default
const mixin = require("mixin-deep")
const passthrough = require("../passthrough")
@ -26,7 +26,7 @@ class MatrixServerError {
* @param {any} [body]
* @param {any} [extra]
*/
function mreq(method, url, body, extra = {}) {
async function mreq(method, url, body, extra = {}) {
const opts = mixin({
method,
body: (body == undefined || Object.is(body.constructor, Object)) ? JSON.stringify(body) : body,
@ -34,13 +34,13 @@ function mreq(method, url, body, extra = {}) {
Authorization: `Bearer ${reg.as_token}`
}
}, extra)
console.log(baseUrl + url, opts)
return fetch(baseUrl + url, opts).then(res => {
return res.json().then(root => {
if (!res.ok || root.errcode) throw new MatrixServerError(root)
return root
})
})
const res = await fetch(baseUrl + url, opts)
const root = await res.json()
if (!res.ok || root.errcode) throw new MatrixServerError(root)
return root
}
module.exports.MatrixServerError = MatrixServerError

View file

@ -3,5 +3,6 @@
const fs = require("fs")
const yaml = require("js-yaml")
/** @type {import("../types").AppServiceRegistrationConfig} */
module.exports = yaml.load(fs.readFileSync("registration.yaml", "utf8"))
/** @ts-ignore @type {import("../types").AppServiceRegistrationConfig} */
const reg = yaml.load(fs.readFileSync("registration.yaml", "utf8"))
module.exports = reg