forked from naskya/firefish
chore: disable reset-db API
This commit is contained in:
parent
233685f3fa
commit
1a0589c19c
3 changed files with 32 additions and 41 deletions
|
@ -40,6 +40,9 @@
|
|||
|
||||
## 細かい変更点
|
||||
|
||||
- `reset-db` という API を無効化
|
||||
- エンドポイント自体は残してありますが、叩いても何もしません
|
||||
- データベースをリセットする API って何?怖すぎる
|
||||
- ユーザーページでプロフィール画像を選択すると画像を拡大する(Catodon から取り込み)
|
||||
- 署名アルゴリズムとして ECDSA や Ed25519 なども受け入れる([github.com/mei23/misskey-v12](https://github.com/mei23/misskey-v12) から取り込み)
|
||||
- Pleroma のチャットに対応(Catodon から取り込み)
|
||||
|
|
|
@ -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;
|
||||
// }
|
||||
// }
|
||||
|
|
|
@ -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 () => {});
|
||||
|
|
Loading…
Reference in a new issue