From d9775c147f9dc5cec208b583a473df06b72305d7 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Fri, 26 Nov 2021 13:41:49 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20tools=E3=81=8C=E5=8B=95=E3=81=8B?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3=20(#8008?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Move tools * Fix DB --- packages/backend/src/tools/add-emoji.ts | 5 ++++- packages/backend/src/tools/demote-admin.ts | 4 +--- packages/backend/src/tools/mark-admin.ts | 4 +--- packages/backend/src/tools/refresh-question.ts | 5 ++++- packages/backend/src/tools/show-signin-history.ts | 5 ++++- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/backend/src/tools/add-emoji.ts b/packages/backend/src/tools/add-emoji.ts index 9ffe7dfa81..6c750bcab0 100644 --- a/packages/backend/src/tools/add-emoji.ts +++ b/packages/backend/src/tools/add-emoji.ts @@ -1,7 +1,10 @@ -import { Emojis } from '@/models/index'; +import { initDb } from '@/db/postgre'; import { genId } from '@/misc/gen-id'; async function main(name: string, url: string, alias?: string): Promise { + await initDb(); + const { Emojis } = await import('@/models/index'); + const aliases = alias != null ? [ alias ] : []; await Emojis.save({ diff --git a/packages/backend/src/tools/demote-admin.ts b/packages/backend/src/tools/demote-admin.ts index d7c6d1cec2..b326c946ef 100644 --- a/packages/backend/src/tools/demote-admin.ts +++ b/packages/backend/src/tools/demote-admin.ts @@ -1,13 +1,11 @@ import { initDb } from '../db/postgre'; -import { getRepository } from 'typeorm'; -import { User } from '@/models/entities/user'; async function main(username: string) { if (!username) throw `username required`; username = username.replace(/^@/, ''); await initDb(); - const Users = getRepository(User); + const { Users } = await import('@/models/index'); const res = await Users.update({ usernameLower: username.toLowerCase(), diff --git a/packages/backend/src/tools/mark-admin.ts b/packages/backend/src/tools/mark-admin.ts index 62ed0f09ee..0833f22266 100644 --- a/packages/backend/src/tools/mark-admin.ts +++ b/packages/backend/src/tools/mark-admin.ts @@ -1,13 +1,11 @@ import { initDb } from '../db/postgre'; -import { getRepository } from 'typeorm'; -import { User } from '@/models/entities/user'; async function main(username: string) { if (!username) throw `username required`; username = username.replace(/^@/, ''); await initDb(); - const Users = getRepository(User); + const { Users } = await import('@/models/index'); const res = await Users.update({ usernameLower: username.toLowerCase(), diff --git a/packages/backend/src/tools/refresh-question.ts b/packages/backend/src/tools/refresh-question.ts index 98a3c2865f..3bbb781ae7 100644 --- a/packages/backend/src/tools/refresh-question.ts +++ b/packages/backend/src/tools/refresh-question.ts @@ -1,6 +1,9 @@ -import { updateQuestion } from '@/remote/activitypub/models/question'; +import { initDb } from '@/db/postgre'; async function main(uri: string): Promise { + await initDb(); + const { updateQuestion } = await import('@/remote/activitypub/models/question'); + return await updateQuestion(uri); } diff --git a/packages/backend/src/tools/show-signin-history.ts b/packages/backend/src/tools/show-signin-history.ts index ad92316314..1291a1b22f 100644 --- a/packages/backend/src/tools/show-signin-history.ts +++ b/packages/backend/src/tools/show-signin-history.ts @@ -1,4 +1,4 @@ -import { Users, Signins } from '@/models/index'; +import { initDb } from '@/db/postgre'; // node built/tools/show-signin-history username // => {Success} {Date} {IPAddrsss} @@ -10,6 +10,9 @@ import { Users, Signins } from '@/models/index'; // with full request headers async function main(username: string, headers?: string[]) { + await initDb(); + const { Users, Signins } = await import('@/models/index'); + const user = await Users.findOne({ host: null, usernameLower: username.toLowerCase(),