From 915c34646afe220c83077dfdd3d92d88f1ece355 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Thu, 12 Sep 2024 17:11:35 +1200 Subject: [PATCH] Fix references from moving all those files --- .gitignore | 2 +- src/d2m/actions/create-room.test.js | 2 +- src/d2m/actions/create-space.test.js | 2 +- src/d2m/actions/register-user.test.js | 2 +- src/d2m/converters/edit-to-changes.test.js | 2 +- src/d2m/converters/emoji-to-key.test.js | 2 +- .../message-to-event.embeds.test.js | 2 +- .../converters/message-to-event.pk.test.js | 2 +- src/d2m/converters/message-to-event.test.js | 2 +- src/d2m/converters/pins-to-list.test.js | 2 +- .../converters/thread-to-announcement.test.js | 2 +- src/d2m/converters/user-to-mxid.test.js | 2 +- .../0011-move-bridge-bot-to-real-id.up.js | 2 +- src/db/migrations/0013-media-proxy.sql | 8 +++ src/db/orm.test.js | 2 +- src/discord/discord-command-handler.js | 4 +- src/discord/register-interactions.js | 2 +- src/discord/utils.test.js | 2 +- src/m2d/converters/event-to-message.test.js | 2 +- src/stdin.js | 4 +- start.js | 18 +++--- test/test.js | 58 +++++++++---------- 22 files changed, 67 insertions(+), 59 deletions(-) create mode 100644 src/db/migrations/0013-media-proxy.sql diff --git a/.gitignore b/.gitignore index 9c175d8f..3781b9b5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,6 @@ node_modules config.js registration.yaml coverage -db/ooye.db* +src/db/ooye.db* test/res/* !test/res/lottie* diff --git a/src/d2m/actions/create-room.test.js b/src/d2m/actions/create-room.test.js index d4391a9d..a1766dd0 100644 --- a/src/d2m/actions/create-room.test.js +++ b/src/d2m/actions/create-room.test.js @@ -4,7 +4,7 @@ const mixin = require("@cloudrac3r/mixin-deep") const {channelToKState, _convertNameAndTopic} = require("./create-room") const {kstateStripConditionals} = require("../../matrix/kstate") const {test} = require("supertape") -const testData = require("../../test/data") +const testData = require("../../../test/data") const passthrough = require("../../passthrough") const {db} = passthrough diff --git a/src/d2m/actions/create-space.test.js b/src/d2m/actions/create-space.test.js index c4111dbd..cb4d90a4 100644 --- a/src/d2m/actions/create-space.test.js +++ b/src/d2m/actions/create-space.test.js @@ -4,7 +4,7 @@ const mixin = require("@cloudrac3r/mixin-deep") const {guildToKState, ensureSpace} = require("./create-space") const {kstateStripConditionals, kstateUploadMxc} = require("../../matrix/kstate") const {test} = require("supertape") -const testData = require("../../test/data") +const testData = require("../../../test/data") const passthrough = require("../../passthrough") const {db} = passthrough diff --git a/src/d2m/actions/register-user.test.js b/src/d2m/actions/register-user.test.js index 96c73aa6..353c89fc 100644 --- a/src/d2m/actions/register-user.test.js +++ b/src/d2m/actions/register-user.test.js @@ -1,6 +1,6 @@ const {_memberToStateContent} = require("./register-user") const {test} = require("supertape") -const testData = require("../../test/data") +const testData = require("../../../test/data") test("member2state: without member nick or avatar", async t => { t.deepEqual( diff --git a/src/d2m/converters/edit-to-changes.test.js b/src/d2m/converters/edit-to-changes.test.js index effb7773..b561bb13 100644 --- a/src/d2m/converters/edit-to-changes.test.js +++ b/src/d2m/converters/edit-to-changes.test.js @@ -1,6 +1,6 @@ const {test} = require("supertape") const {editToChanges} = require("./edit-to-changes") -const data = require("../../test/data") +const data = require("../../../test/data") const Ty = require("../../types") test("edit2changes: edit by webhook", async t => { diff --git a/src/d2m/converters/emoji-to-key.test.js b/src/d2m/converters/emoji-to-key.test.js index 5af046c0..544eadae 100644 --- a/src/d2m/converters/emoji-to-key.test.js +++ b/src/d2m/converters/emoji-to-key.test.js @@ -2,7 +2,7 @@ const {test} = require("supertape") const {emojiToKey} = require("./emoji-to-key") -const data = require("../../test/data") +const data = require("../../../test/data") const Ty = require("../../types") test("emoji2key: unicode emoji works", async t => { diff --git a/src/d2m/converters/message-to-event.embeds.test.js b/src/d2m/converters/message-to-event.embeds.test.js index 05e3b5d5..ef7e9b8d 100644 --- a/src/d2m/converters/message-to-event.embeds.test.js +++ b/src/d2m/converters/message-to-event.embeds.test.js @@ -1,6 +1,6 @@ const {test} = require("supertape") const {messageToEvent} = require("./message-to-event") -const data = require("../../test/data") +const data = require("../../../test/data") const Ty = require("../../types") test("message2event embeds: nothing but a field", async t => { diff --git a/src/d2m/converters/message-to-event.pk.test.js b/src/d2m/converters/message-to-event.pk.test.js index c4904694..ce83d544 100644 --- a/src/d2m/converters/message-to-event.pk.test.js +++ b/src/d2m/converters/message-to-event.pk.test.js @@ -1,6 +1,6 @@ const {test} = require("supertape") const {messageToEvent} = require("./message-to-event") -const data = require("../../test/data") +const data = require("../../../test/data") const Ty = require("../../types") /** diff --git a/src/d2m/converters/message-to-event.test.js b/src/d2m/converters/message-to-event.test.js index 02fb4bb2..3df1130e 100644 --- a/src/d2m/converters/message-to-event.test.js +++ b/src/d2m/converters/message-to-event.test.js @@ -1,6 +1,6 @@ const {test} = require("supertape") const {messageToEvent} = require("./message-to-event") -const data = require("../../test/data") +const data = require("../../../test/data") const Ty = require("../../types") /** diff --git a/src/d2m/converters/pins-to-list.test.js b/src/d2m/converters/pins-to-list.test.js index 8a6daea1..7ee89b6d 100644 --- a/src/d2m/converters/pins-to-list.test.js +++ b/src/d2m/converters/pins-to-list.test.js @@ -1,5 +1,5 @@ const {test} = require("supertape") -const data = require("../../test/data") +const data = require("../../../test/data") const {pinsToList} = require("./pins-to-list") test("pins2list: converts known IDs, ignores unknown IDs", t => { diff --git a/src/d2m/converters/thread-to-announcement.test.js b/src/d2m/converters/thread-to-announcement.test.js index 3bbca205..471cd943 100644 --- a/src/d2m/converters/thread-to-announcement.test.js +++ b/src/d2m/converters/thread-to-announcement.test.js @@ -1,6 +1,6 @@ const {test} = require("supertape") const {threadToAnnouncement} = require("./thread-to-announcement") -const data = require("../../test/data") +const data = require("../../../test/data") const Ty = require("../../types") /** diff --git a/src/d2m/converters/user-to-mxid.test.js b/src/d2m/converters/user-to-mxid.test.js index 5787b649..86f151b6 100644 --- a/src/d2m/converters/user-to-mxid.test.js +++ b/src/d2m/converters/user-to-mxid.test.js @@ -1,7 +1,7 @@ const {test} = require("supertape") const tryToCatch = require("try-to-catch") const assert = require("assert") -const data = require("../../test/data") +const data = require("../../../test/data") const {userToSimName} = require("./user-to-mxid") test("user2name: cannot create user for a webhook", async t => { diff --git a/src/db/migrations/0011-move-bridge-bot-to-real-id.up.js b/src/db/migrations/0011-move-bridge-bot-to-real-id.up.js index 1808fcdb..6bcf2c75 100644 --- a/src/db/migrations/0011-move-bridge-bot-to-real-id.up.js +++ b/src/db/migrations/0011-move-bridge-bot-to-real-id.up.js @@ -10,7 +10,7 @@ */ module.exports = async function(db) { - const config = require("../../config") + const config = require("../../../config") const id = Buffer.from(config.discordToken.split(".")[0], "base64").toString() db.prepare("UPDATE OR REPLACE sim SET user_id = ? WHERE user_id = '0'").run(id) } diff --git a/src/db/migrations/0013-media-proxy.sql b/src/db/migrations/0013-media-proxy.sql new file mode 100644 index 00000000..d55f0594 --- /dev/null +++ b/src/db/migrations/0013-media-proxy.sql @@ -0,0 +1,8 @@ +BEGIN TRANSACTION; + +CREATE TABLE "media_proxy" ( + "permitted_hash" INTEGER NOT NULL, + PRIMARY KEY("permitted_hash") +) WITHOUT ROWID; + +COMMIT; diff --git a/src/db/orm.test.js b/src/db/orm.test.js index 3d4e8efd..a53cc660 100644 --- a/src/db/orm.test.js +++ b/src/db/orm.test.js @@ -1,7 +1,7 @@ // @ts-check const {test} = require("supertape") -const data = require("../test/data") +const data = require("../../test/data") const {db, select, from} = require("../passthrough") diff --git a/src/discord/discord-command-handler.js b/src/discord/discord-command-handler.js index d9ad80fa..f0a4b49c 100644 --- a/src/discord/discord-command-handler.js +++ b/src/discord/discord-command-handler.js @@ -4,7 +4,7 @@ const assert = require("assert").strict const util = require("util") const DiscordTypes = require("discord-api-types/v10") const {reg} = require("../matrix/read-registration") -const {addbot} = require("../addbot") +const {addbot} = require("../../addbot") const {discord, sync, db, select} = require("../passthrough") /** @type {import("../matrix/api")}) */ @@ -12,7 +12,7 @@ const api = sync.require("../matrix/api") /** @type {import("../matrix/file")} */ const file = sync.require("../matrix/file") /** @type {import("../m2d/converters/utils")} */ -const mxUtils = sync.require("../matrix/utils") +const mxUtils = sync.require("../m2d/converters/utils") /** @type {import("../d2m/actions/create-space")} */ const createSpace = sync.require("../d2m/actions/create-space") /** @type {import("./utils")} */ diff --git a/src/discord/register-interactions.js b/src/discord/register-interactions.js index 026ac7a7..c66bef39 100644 --- a/src/discord/register-interactions.js +++ b/src/discord/register-interactions.js @@ -2,7 +2,7 @@ const DiscordTypes = require("discord-api-types/v10") const {discord, sync, db, select} = require("../passthrough") -const {id} = require("../addbot") +const {id} = require("../../addbot") const matrixInfo = sync.require("./interactions/matrix-info.js") const invite = sync.require("./interactions/invite.js") diff --git a/src/discord/utils.test.js b/src/discord/utils.test.js index 815c0a10..7c5f0c89 100644 --- a/src/discord/utils.test.js +++ b/src/discord/utils.test.js @@ -1,6 +1,6 @@ const DiscordTypes = require("discord-api-types/v10") const {test} = require("supertape") -const data = require("../test/data") +const data = require("../../test/data") const utils = require("./utils") test("is webhook message: identifies bot interaction response as not a message", t => { diff --git a/src/m2d/converters/event-to-message.test.js b/src/m2d/converters/event-to-message.test.js index d6a20cd0..b6748458 100644 --- a/src/m2d/converters/event-to-message.test.js +++ b/src/m2d/converters/event-to-message.test.js @@ -3,7 +3,7 @@ const fs = require("fs") const {test} = require("supertape") const {eventToMessage} = require("./event-to-message") const {convertImageStream} = require("./emoji-sheet") -const data = require("../../test/data") +const data = require("../../../test/data") const {MatrixServerError} = require("../../matrix/mreq") const {select, discord} = require("../../passthrough") diff --git a/src/stdin.js b/src/stdin.js index 780b9dc0..cabd8ced 100644 --- a/src/stdin.js +++ b/src/stdin.js @@ -2,12 +2,12 @@ const repl = require("repl") const util = require("util") -const {addbot} = require("./addbot") +const {addbot} = require("../addbot") const passthrough = require("./passthrough") const {discord, config, sync, db} = passthrough -const data = sync.require("./test/data") +const data = sync.require("../test/data") const createSpace = sync.require("./d2m/actions/create-space") const createRoom = sync.require("./d2m/actions/create-room") const registerUser = sync.require("./d2m/actions/register-user") diff --git a/start.js b/start.js index 1ece1ddc..d6bd4c9d 100644 --- a/start.js +++ b/start.js @@ -1,32 +1,32 @@ // @ts-check const sqlite = require("better-sqlite3") -const migrate = require("./db/migrate") +const migrate = require("./src/db/migrate") const HeatSync = require("heatsync") const config = require("./config") -const passthrough = require("./passthrough") -const db = new sqlite("db/ooye.db") +const passthrough = require("./src/passthrough") +const db = new sqlite("src/db/ooye.db") /** @type {import("heatsync").default} */ // @ts-ignore const sync = new HeatSync() Object.assign(passthrough, {config, sync, db}) -const DiscordClient = require("./d2m/discord-client") +const DiscordClient = require("./src/d2m/discord-client") const discord = new DiscordClient(config.discordToken, "full") passthrough.discord = discord -const {as} = require("./matrix/appservice") +const {as} = require("./src/matrix/appservice") passthrough.as = as -const orm = sync.require("./db/orm") +const orm = sync.require("./src/db/orm") passthrough.from = orm.from passthrough.select = orm.select -const power = require("./matrix/power.js") -sync.require("./m2d/event-dispatcher") +const power = require("./src/matrix/power.js") +sync.require("./src/m2d/event-dispatcher") ;(async () => { await migrate.migrate(db) @@ -34,5 +34,5 @@ sync.require("./m2d/event-dispatcher") console.log("Discord gateway started") await power.applyPower() - require("./stdin") + require("./src/stdin") })() diff --git a/test/test.js b/test/test.js index c2b703dc..c898ad1f 100644 --- a/test/test.js +++ b/test/test.js @@ -4,7 +4,7 @@ const fs = require("fs") const {join} = require("path") const stp = require("stream").promises const sqlite = require("better-sqlite3") -const migrate = require("../db/migrate") +const migrate = require("../src/db/migrate") const HeatSync = require("heatsync") const {test} = require("supertape") const data = require("./data") @@ -14,10 +14,10 @@ const fetch = require("node-fetch") const {green} = require("colorette") const config = require("../config") -const passthrough = require("../passthrough") +const passthrough = require("../src/passthrough") const db = new sqlite(":memory:") -const {reg} = require("../matrix/read-registration") +const {reg} = require("../src/matrix/read-registration") reg.ooye.server_origin = "https://matrix.cadence.moe" // so that tests will pass even when hard-coded reg.ooye.server_name = "cadence.moe" reg.id = "baby" // don't actually take authenticated actions on the server @@ -48,11 +48,11 @@ const discord = { Object.assign(passthrough, { discord, config, sync, db }) -const orm = sync.require("../db/orm") +const orm = sync.require("../src/db/orm") passthrough.from = orm.from passthrough.select = orm.select -const file = sync.require("../matrix/file") +const file = sync.require("../src/matrix/file") /* c8 ignore next */ file._actuallyUploadDiscordFileToMxc = function(url, res) { throw new Error(`Not allowed to upload files during testing.\nURL: ${url}`) } @@ -113,28 +113,28 @@ file._actuallyUploadDiscordFileToMxc = function(url, res) { throw new Error(`Not db.exec(fs.readFileSync(join(__dirname, "ooye-test-data.sql"), "utf8")) - require("../db/orm.test") - require("../discord/utils.test") - require("../matrix/kstate.test") - require("../matrix/api.test") - require("../matrix/file.test") - //require("../matrix/power.test") - require("../matrix/read-registration.test") - require("../matrix/txnid.test") - require("../d2m/actions/create-room.test") - require("../d2m/actions/create-space.test") - require("../d2m/actions/register-user.test") - require("../d2m/converters/edit-to-changes.test") - require("../d2m/converters/emoji-to-key.test") - require("../d2m/converters/lottie.test") - require("../d2m/converters/message-to-event.test") - require("../d2m/converters/message-to-event.embeds.test") - require("../d2m/converters/message-to-event.pk.test") - require("../d2m/converters/pins-to-list.test") - require("../d2m/converters/remove-reaction.test") - require("../d2m/converters/thread-to-announcement.test") - require("../d2m/converters/user-to-mxid.test") - require("../m2d/converters/event-to-message.test") - require("../m2d/converters/utils.test") - require("../m2d/converters/emoji-sheet.test") + require("../src/db/orm.test") + require("../src/discord/utils.test") + require("../src/matrix/kstate.test") + require("../src/matrix/api.test") + require("../src/matrix/file.test") + require("../src/matrix/power.test") + require("../src/matrix/read-registration.test") + require("../src/matrix/txnid.test") + require("../src/d2m/actions/create-room.test") + require("../src/d2m/actions/create-space.test") + require("../src/d2m/actions/register-user.test") + require("../src/d2m/converters/edit-to-changes.test") + require("../src/d2m/converters/emoji-to-key.test") + require("../src/d2m/converters/lottie.test") + require("../src/d2m/converters/message-to-event.test") + require("../src/d2m/converters/message-to-event.embeds.test") + require("../src/d2m/converters/message-to-event.pk.test") + require("../src/d2m/converters/pins-to-list.test") + require("../src/d2m/converters/remove-reaction.test") + require("../src/d2m/converters/thread-to-announcement.test") + require("../src/d2m/converters/user-to-mxid.test") + require("../src/m2d/converters/event-to-message.test") + require("../src/m2d/converters/utils.test") + require("../src/m2d/converters/emoji-sheet.test") })()