mirror of
https://gitdab.com/cadence/out-of-your-element.git
synced 2025-09-10 12:22:50 +02:00
Interactive initial setup
This commit is contained in:
parent
e0bb19bfab
commit
37f3a59d8e
24 changed files with 249 additions and 43 deletions
|
@ -1,6 +1,6 @@
|
|||
// @ts-check
|
||||
|
||||
const reg = require("../matrix/read-registration")
|
||||
const {reg} = require("../matrix/read-registration")
|
||||
const {AppService} = require("@cloudrac3r/in-your-element")
|
||||
const as = new AppService(reg)
|
||||
as.listen()
|
||||
|
|
|
@ -14,7 +14,7 @@ const mxUtils = sync.require("../m2d/converters/utils")
|
|||
const dUtils = sync.require("../discord/utils")
|
||||
/** @type {import("./kstate")} */
|
||||
const ks = sync.require("./kstate")
|
||||
const reg = require("./read-registration")
|
||||
const {reg} = require("./read-registration")
|
||||
|
||||
const PREFIXES = ["//", "/"]
|
||||
|
||||
|
|
|
@ -5,10 +5,7 @@ const mixin = require("@cloudrac3r/mixin-deep")
|
|||
const stream = require("stream")
|
||||
const getStream = require("get-stream")
|
||||
|
||||
const passthrough = require("../passthrough")
|
||||
const { sync } = passthrough
|
||||
/** @type {import("./read-registration")} */
|
||||
const reg = sync.require("./read-registration.js")
|
||||
const {reg} = require("./read-registration.js")
|
||||
|
||||
const baseUrl = `${reg.ooye.server_origin}/_matrix`
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// @ts-check
|
||||
|
||||
const {db, from} = require("../passthrough")
|
||||
const reg = require("./read-registration")
|
||||
const {reg} = require("./read-registration")
|
||||
const ks = require("./kstate")
|
||||
const {applyKStateDiffToRoom, roomToKState} = require("../d2m/actions/create-room")
|
||||
|
||||
|
|
|
@ -1,14 +1,85 @@
|
|||
// @ts-check
|
||||
|
||||
const fs = require("fs")
|
||||
const crypto = require("crypto")
|
||||
const assert = require("assert").strict
|
||||
const path = require("path")
|
||||
const yaml = require("js-yaml")
|
||||
|
||||
/** @ts-ignore @type {import("../types").AppServiceRegistrationConfig} */
|
||||
const reg = yaml.load(fs.readFileSync("registration.yaml", "utf8"))
|
||||
reg["ooye"].invite = (reg.ooye.invite || []).filter(mxid => mxid.endsWith(`:${reg.ooye.server_name}`)) // one day I will understand why typescript disagrees with dot notation on this line
|
||||
assert(reg.ooye.max_file_size)
|
||||
assert(reg.ooye.namespace_prefix)
|
||||
assert(reg.ooye.server_name)
|
||||
const registrationFilePath = path.join(process.cwd(), "registration.yaml")
|
||||
|
||||
module.exports = reg
|
||||
/** @param {import("../types").AppServiceRegistrationConfig} reg */
|
||||
function checkRegistration(reg) {
|
||||
reg["ooye"].invite = (reg.ooye.invite || []).filter(mxid => mxid.endsWith(`:${reg.ooye.server_name}`)) // one day I will understand why typescript disagrees with dot notation on this line
|
||||
assert(reg.ooye?.max_file_size)
|
||||
assert(reg.ooye?.namespace_prefix)
|
||||
assert(reg.ooye?.server_name)
|
||||
assert(reg.sender_localpart?.startsWith(reg.ooye.namespace_prefix), "appservice's localpart must be in the namespace it controls")
|
||||
assert(reg.ooye?.server_origin.match(/^https?:\/\//), "server origin must start with http or https")
|
||||
assert.notEqual(reg.ooye?.server_origin.slice(-1), "/", "server origin must not end in slash")
|
||||
assert.match(reg.url, /^https?:/, "url must start with http:// or https://")
|
||||
}
|
||||
|
||||
/** @param {import("../types").AppServiceRegistrationConfig} reg */
|
||||
function writeRegistration(reg) {
|
||||
fs.writeFileSync(registrationFilePath, JSON.stringify(reg, null, 2))
|
||||
}
|
||||
|
||||
/** @returns {import("../types").InitialAppServiceRegistrationConfig} reg */
|
||||
function getTemplateRegistration() {
|
||||
return {
|
||||
id: crypto.randomBytes(16).toString("hex"),
|
||||
as_token: crypto.randomBytes(16).toString("hex"),
|
||||
hs_token: crypto.randomBytes(16).toString("hex"),
|
||||
namespaces: {
|
||||
users: [{
|
||||
exclusive: true,
|
||||
regex: "@_ooye_.*:cadence.moe"
|
||||
}],
|
||||
aliases: [{
|
||||
exclusive: true,
|
||||
regex: "#_ooye_.*:cadence.moe"
|
||||
}]
|
||||
},
|
||||
protocols: [
|
||||
"discord"
|
||||
],
|
||||
sender_localpart: "_ooye_bot",
|
||||
rate_limited: false,
|
||||
ooye: {
|
||||
namespace_prefix: "_ooye_",
|
||||
max_file_size: 5000000,
|
||||
content_length_workaround: false,
|
||||
include_user_id_in_mxid: false,
|
||||
invite: []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function readRegistration() {
|
||||
/** @type {import("../types").AppServiceRegistrationConfig} */ // @ts-ignore
|
||||
let result = null
|
||||
if (fs.existsSync(registrationFilePath)) {
|
||||
const content = fs.readFileSync(registrationFilePath, "utf8")
|
||||
if (content.startsWith("{")) { // Use JSON parser
|
||||
result = JSON.parse(content)
|
||||
checkRegistration(result)
|
||||
} else { // Use YAML parser
|
||||
result = yaml.load(content)
|
||||
checkRegistration(result)
|
||||
// Convert to JSON
|
||||
writeRegistration(result)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** @type {import("../types").AppServiceRegistrationConfig} */ // @ts-ignore
|
||||
let reg = readRegistration()
|
||||
|
||||
module.exports.registrationFilePath = registrationFilePath
|
||||
module.exports.readRegistration = readRegistration
|
||||
module.exports.getTemplateRegistration = getTemplateRegistration
|
||||
module.exports.writeRegistration = writeRegistration
|
||||
module.exports.checkRegistration = checkRegistration
|
||||
module.exports.reg = reg
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const {test} = require("supertape")
|
||||
const reg = require("./read-registration")
|
||||
const {reg} = require("./read-registration")
|
||||
|
||||
test("reg: has necessary parameters", t => {
|
||||
const propertiesToCheck = ["sender_localpart", "id", "as_token", "ooye"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue