mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 12:22:14 +03:00
Extrai 7 grupos de comandos do monolito bin/cli-commands.mjs (2853 linhas)
para módulos individuais em bin/cli/commands/, registrados via Commander.
- stop.mjs: SIGTERM/SIGKILL via process.kill(); fallback por porta usa execFile
com array de args (evita injeção de shell / Semgrep CWE-78)
- restart.mjs: delega para runStopCommand + runServe
- dashboard.mjs: alias "open", fallback nativo por plataforma via execFile
- keys.mjs: server-first (POST /api/v1/providers/keys) → DB fallback; valida
provider via loadAvailableProviders(); suporte a --stdin
- models.mjs: GET /api/models → fallback /api/v1/models; filtro por provider e --search
- combo.mjs: list/switch/create/delete; switch server-first → DB fallback via key_value;
TODO(1.5) marcados para substituir SQL cru por src/lib/db/combos.ts
- serve.mjs: escreve PID via writePidFile() no spawn; limpa no shutdown; suporte daemon
utils/pid.mjs e i18n keys (en.json + pt-BR.json) já criados em iteração anterior.
Testes: cli-keys-command.test.ts atualizado para novos runners;
cli-serve-stop-command.test.ts, cli-combo-command.test.ts,
cli-models-command.test.ts adicionados (23 testes, 0 falhas).
26 lines
677 B
JavaScript
26 lines
677 B
JavaScript
import { t } from "../i18n.mjs";
|
|
import { runStopCommand } from "./stop.mjs";
|
|
import { sleep } from "../utils/pid.mjs";
|
|
|
|
export function registerRestart(program) {
|
|
program
|
|
.command("restart")
|
|
.description(t("restart.description"))
|
|
.option("--port <port>", t("serve.port"), "20128")
|
|
.action(async (opts) => {
|
|
const exitCode = await runRestartCommand(opts);
|
|
if (exitCode !== 0) process.exit(exitCode);
|
|
});
|
|
}
|
|
|
|
export async function runRestartCommand(opts = {}) {
|
|
console.log(t("restart.restarting"));
|
|
|
|
await runStopCommand(opts);
|
|
await sleep(1000);
|
|
|
|
const { runServe } = await import("./serve.mjs");
|
|
await runServe(opts);
|
|
return 0;
|
|
}
|