From 1a0589c19c0bb4056e5786e6061ac4ad2a285e0d Mon Sep 17 00:00:00 2001 From: naskya Date: Wed, 10 Jan 2024 14:19:03 +0900 Subject: [PATCH] chore: disable reset-db API --- README.md | 3 ++ packages/backend/src/db/postgre.ts | 52 +++++++++---------- .../src/server/api/endpoints/reset-db.ts | 18 ++----- 3 files changed, 32 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 32f4310e1..3746a77f5 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,9 @@ ## 細かい変更点 +- `reset-db` という API を無効化 + - エンドポイント自体は残してありますが、叩いても何もしません + - データベースをリセットする API って何?怖すぎる - ユーザーページでプロフィール画像を選択すると画像を拡大する(Catodon から取り込み) - 署名アルゴリズムとして ECDSA や Ed25519 なども受け入れる([github.com/mei23/misskey-v12](https://github.com/mei23/misskey-v12) から取り込み) - Pleroma のチャットに対応(Catodon から取り込み) diff --git a/packages/backend/src/db/postgre.ts b/packages/backend/src/db/postgre.ts index b14f028e8..9ec52bb77 100644 --- a/packages/backend/src/db/postgre.ts +++ b/packages/backend/src/db/postgre.ts @@ -236,30 +236,30 @@ export async function initDb(force = false) { } } -export async function resetDb() { - const reset = async () => { - await redisClient.flushdb(); - const tables = await db.query(`SELECT relname AS "table" - FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) - WHERE nspname NOT IN ('pg_catalog', 'information_schema') - AND C.relkind = 'r' - AND nspname !~ '^pg_toast';`); - for (const table of tables) { - await db.query(`DELETE FROM "${table.table}" CASCADE`); - } - }; +// export async function resetDb() { +// const reset = async () => { +// await redisClient.flushdb(); +// const tables = await db.query(`SELECT relname AS "table" +// FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) +// WHERE nspname NOT IN ('pg_catalog', 'information_schema') +// AND C.relkind = 'r' +// AND nspname !~ '^pg_toast';`); +// for (const table of tables) { +// await db.query(`DELETE FROM "${table.table}" CASCADE`); +// } +// }; - for (let i = 1; i <= 3; i++) { - try { - await reset(); - } catch (e) { - if (i === 3) { - throw e; - } else { - await new Promise((resolve) => setTimeout(resolve, 1000)); - continue; - } - } - break; - } -} +// for (let i = 1; i <= 3; i++) { +// try { +// await reset(); +// } catch (e) { +// if (i === 3) { +// throw e; +// } else { +// await new Promise((resolve) => setTimeout(resolve, 1000)); +// continue; +// } +// } +// break; +// } +// } diff --git a/packages/backend/src/server/api/endpoints/reset-db.ts b/packages/backend/src/server/api/endpoints/reset-db.ts index daba09b8e..1a12420c1 100644 --- a/packages/backend/src/server/api/endpoints/reset-db.ts +++ b/packages/backend/src/server/api/endpoints/reset-db.ts @@ -1,15 +1,10 @@ -import { resetDb } from "@/db/postgre.js"; +// import { resetDb } from "@/db/postgre.js"; import define from "@/server/api/define.js"; export const meta = { tags: ["non-productive"], - requireCredential: false, - - description: - "Only available when running with NODE_ENV=testing. Reset the database and flush Redis.", - - errors: {}, + description: "Do nothing.", } as const; export const paramDef = { @@ -18,11 +13,4 @@ export const paramDef = { required: [], } as const; -export default define(meta, paramDef, async (ps, user) => { - if (process.env.NODE_ENV !== "test") - throw new Error("NODE_ENV is not a test"); - - await resetDb(); - - await new Promise((resolve) => setTimeout(resolve, 1000)); -}); +export default define(meta, paramDef, async () => {});