summaryrefslogtreecommitdiff
path: root/packages/backend
diff options
context:
space:
mode:
authorsyuilo <4439005+syuilo@users.noreply.github.com>2025-08-20 16:35:26 +0900
committerGitHub <noreply@github.com>2025-08-20 16:35:26 +0900
commitb07bf838e36dd5cc4b4d2533229d88bb3ba85481 (patch)
tree9697e782147ec9e73de7ece941de43fbcca3f948 /packages/backend
parentfix(frontend): 読み込み直後にプラグインによるノートの書... (diff)
downloadmisskey-b07bf838e36dd5cc4b4d2533229d88bb3ba85481.tar.gz
misskey-b07bf838e36dd5cc4b4d2533229d88bb3ba85481.tar.bz2
misskey-b07bf838e36dd5cc4b4d2533229d88bb3ba85481.zip
サーバー管理コマンド (#15882)
* wip * Update cli.ts * Update cli.ts * wip * Update CHANGELOG.md * Delete cli.mjs
Diffstat (limited to 'packages/backend')
-rw-r--r--packages/backend/package.json1
-rw-r--r--packages/backend/src/boot/cli.ts49
-rw-r--r--packages/backend/src/cli/CommandModule.ts23
-rw-r--r--packages/backend/src/cli/CommandService.ts49
4 files changed, 122 insertions, 0 deletions
diff --git a/packages/backend/package.json b/packages/backend/package.json
index 0d1ae4ac3d..39ea07125d 100644
--- a/packages/backend/package.json
+++ b/packages/backend/package.json
@@ -11,6 +11,7 @@
"start:test": "cross-env NODE_ENV=test node ./built/boot/entry.js",
"migrate": "pnpm typeorm migration:run -d ormconfig.js",
"revert": "pnpm typeorm migration:revert -d ormconfig.js",
+ "cli": "node ./built/boot/cli.js",
"check:connect": "node ./scripts/check_connect.js",
"build": "swc src -d built -D --strip-leading-paths",
"build:test": "swc test-server -d built-test -D --config-file test-server/.swcrc --strip-leading-paths",
diff --git a/packages/backend/src/boot/cli.ts b/packages/backend/src/boot/cli.ts
new file mode 100644
index 0000000000..a5618f8152
--- /dev/null
+++ b/packages/backend/src/boot/cli.ts
@@ -0,0 +1,49 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and misskey-project
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+import 'reflect-metadata';
+import { EventEmitter } from 'node:events';
+import { NestFactory } from '@nestjs/core';
+import { CommandModule } from '@/cli/CommandModule.js';
+import { NestLogger } from '@/NestLogger.js';
+import { CommandService } from '@/cli/CommandService.js';
+
+process.title = 'Misskey Cli';
+
+Error.stackTraceLimit = Infinity;
+EventEmitter.defaultMaxListeners = 128;
+
+const app = await NestFactory.createApplicationContext(CommandModule, {
+ logger: new NestLogger(),
+});
+
+const commandService = app.get(CommandService);
+
+const command = process.argv[2] ?? 'help';
+
+switch (command) {
+ case 'help': {
+ console.log('Available commands:');
+ console.log(' help - Displays this help message');
+ console.log(' reset-captcha - Resets the captcha');
+ break;
+ }
+ case 'ping': {
+ await commandService.ping();
+ break;
+ }
+ case 'reset-captcha': {
+ await commandService.resetCaptcha();
+ console.log('Captcha has been reset.');
+ break;
+ }
+ default: {
+ console.error(`Unrecognized command: ${command}`);
+ console.error('Use "help" to see available commands.');
+ process.exit(1);
+ }
+}
+
+process.exit(0);
diff --git a/packages/backend/src/cli/CommandModule.ts b/packages/backend/src/cli/CommandModule.ts
new file mode 100644
index 0000000000..f4b1d25c18
--- /dev/null
+++ b/packages/backend/src/cli/CommandModule.ts
@@ -0,0 +1,23 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and misskey-project
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+import { Module } from '@nestjs/common';
+import { CoreModule } from '@/core/CoreModule.js';
+import { GlobalModule } from '@/GlobalModule.js';
+import { CommandService } from './CommandService.js';
+
+@Module({
+ imports: [
+ GlobalModule,
+ CoreModule,
+ ],
+ providers: [
+ CommandService,
+ ],
+ exports: [
+ CommandService,
+ ],
+})
+export class CommandModule {}
diff --git a/packages/backend/src/cli/CommandService.ts b/packages/backend/src/cli/CommandService.ts
new file mode 100644
index 0000000000..cdb2a9f382
--- /dev/null
+++ b/packages/backend/src/cli/CommandService.ts
@@ -0,0 +1,49 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and misskey-project
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+import { Inject, Injectable } from '@nestjs/common';
+import type { Config } from '@/config.js';
+import { DI } from '@/di-symbols.js';
+import type Logger from '@/logger.js';
+import { bindThis } from '@/decorators.js';
+import { MetaService } from '@/core/MetaService.js';
+
+@Injectable()
+export class CommandService {
+ private logger: Logger;
+
+ constructor(
+ @Inject(DI.config)
+ private config: Config,
+
+ private metaService: MetaService,
+ ) {
+ }
+
+ @bindThis
+ public async ping() {
+ console.log('pong');
+ }
+
+ @bindThis
+ public async resetCaptcha() {
+ await this.metaService.update({
+ enableHcaptcha: false,
+ hcaptchaSiteKey: null,
+ hcaptchaSecretKey: null,
+ enableMcaptcha: false,
+ mcaptchaSitekey: null,
+ mcaptchaSecretKey: null,
+ mcaptchaInstanceUrl: null,
+ enableRecaptcha: false,
+ recaptchaSiteKey: null,
+ recaptchaSecretKey: null,
+ enableTurnstile: false,
+ turnstileSiteKey: null,
+ turnstileSecretKey: null,
+ enableTestcaptcha: false,
+ });
+ }
+}