diff --git a/package-lock.json b/package-lock.json index c9d0574..bf6f81c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,7 @@ "get-stream": "^6.0.1", "h3": "^1.12.0", "heatsync": "^2.5.3", + "js-yaml": "^4.1.0", "minimist": "^1.2.8", "node-fetch": "^2.6.7", "prettier-bytes": "^1.0.4", @@ -1016,6 +1017,11 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + }, "node_modules/as-table": { "version": "1.0.55", "resolved": "https://registry.npmjs.org/as-table/-/as-table-1.0.55.tgz", @@ -1925,6 +1931,17 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, "node_modules/just-kebab-case": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/just-kebab-case/-/just-kebab-case-4.2.0.tgz", diff --git a/package.json b/package.json index 3fd7651..5933ba9 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "get-stream": "^6.0.1", "h3": "^1.12.0", "heatsync": "^2.5.3", + "js-yaml": "^4.1.0", "minimist": "^1.2.8", "node-fetch": "^2.6.7", "prettier-bytes": "^1.0.4", diff --git a/scripts/seed.js b/scripts/seed.js index 55ada69..16be900 100755 --- a/scripts/seed.js +++ b/scripts/seed.js @@ -87,9 +87,6 @@ async function validateHomeserverOrigin(serverUrlPrompt, url) { if (res.status !== 200) return `There is no Matrix server at that URL (${url}/_matrix/client/versions returned ${res.status})` try { var json = await res.json() - if (!Array.isArray(json?.versions) || !json.versions.includes("v1.11")) { - return `OOYE needs Matrix version v1.11, but ${url} doesn't support this` - } } catch (e) { return `There is no Matrix server at that URL (${url}/_matrix/client/versions is not JSON)` } diff --git a/src/matrix/read-registration.js b/src/matrix/read-registration.js index 8438387..9efffdf 100644 --- a/src/matrix/read-registration.js +++ b/src/matrix/read-registration.js @@ -4,6 +4,7 @@ const fs = require("fs") const crypto = require("crypto") const assert = require("assert").strict const path = require("path") +const yaml = require("js-yaml") const registrationFilePath = path.join(process.cwd(), "registration.yaml") @@ -59,10 +60,18 @@ function getTemplateRegistration() { function readRegistration() { /** @type {import("../types").AppServiceRegistrationConfig} */ // @ts-ignore let result = null - try { + if (fs.existsSync(registrationFilePath)) { const content = fs.readFileSync(registrationFilePath, "utf8") - result = JSON.parse(content) - } catch (e) {} + 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 }