1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-11-25 15:46:39 +09:00
This commit is contained in:
syuilo 2021-11-12 13:39:57 +09:00
parent 0484976afa
commit 4786214e2a
2 changed files with 31 additions and 7 deletions

View File

@ -215,11 +215,27 @@ export function initDb(justBorrow = false, sync = false, forceRecreate = false)
} }
export async function resetDb() { export async function resetDb() {
const conn = await getConnection(); const reset = async () => {
const tables = await conn.query(`SELECT relname AS "table" const conn = await getConnection();
FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) const tables = await conn.query(`SELECT relname AS "table"
WHERE nspname NOT IN ('pg_catalog', 'information_schema') FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
AND C.relkind = 'r' WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND nspname !~ '^pg_toast';`); AND C.relkind = 'r'
await Promise.all(tables.map(t => t.table).map(x => conn.query(`DELETE FROM "${x}" CASCADE`))); AND nspname !~ '^pg_toast';`);
await Promise.all(tables.map(t => t.table).map(x => conn.query(`DELETE FROM "${x}" 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;
}
} }

View File

@ -23,6 +23,7 @@ const _filename = __filename;
const _dirname = dirname(_filename); const _dirname = dirname(_filename);
const staticAssets = `${_dirname}/../../../assets/`; const staticAssets = `${_dirname}/../../../assets/`;
const clientAssets = `${_dirname}/../../../../client/assets/`;
const assets = `${_dirname}/../../../../../built/_client_dist_/`; const assets = `${_dirname}/../../../../../built/_client_dist_/`;
// Init app // Init app
@ -59,6 +60,13 @@ router.get('/static-assets/(.*)', async ctx => {
}); });
}); });
router.get('/client-assets/(.*)', async ctx => {
await send(ctx as any, ctx.path.replace('/client-assets/', ''), {
root: clientAssets,
maxage: ms('7 days'),
});
});
router.get('/assets/(.*)', async ctx => { router.get('/assets/(.*)', async ctx => {
await send(ctx as any, ctx.path.replace('/assets/', ''), { await send(ctx as any, ctx.path.replace('/assets/', ''), {
root: assets, root: assets,