chore: disable reset-db API

This commit is contained in:
naskya 2024-01-10 14:19:03 +09:00
parent 233685f3fa
commit 1a0589c19c
Signed by: naskya
GPG key ID: 712D413B3A9FED5C
3 changed files with 32 additions and 41 deletions

View file

@ -40,6 +40,9 @@
## 細かい変更点
- `reset-db` という API を無効化
- エンドポイント自体は残してありますが、叩いても何もしません
- データベースをリセットする API って何?怖すぎる
- ユーザーページでプロフィール画像を選択すると画像を拡大するCatodon から取り込み)
- 署名アルゴリズムとして ECDSA や Ed25519 なども受け入れる([github.com/mei23/misskey-v12](https://github.com/mei23/misskey-v12) から取り込み)
- Pleroma のチャットに対応Catodon から取り込み)

View file

@ -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;
// }
// }

View file

@ -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 <code>NODE_ENV=testing</code>. 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 () => {});