mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-04 14:22:09 +03:00
Same root cause as commit 49fe356b9: ChatPlayground filtered models
with m.id.startsWith(...) which crashed on null/undefined ids returned
by /v1/models (synthetic combo entries). Apply the same defensive guard
and dedupe used in the parent page.
79 lines
2.1 KiB
JavaScript
79 lines
2.1 KiB
JavaScript
#!/usr/bin/env node
|
||
|
||
/**
|
||
* Password Reset CLI — T-38
|
||
*
|
||
* Usage:
|
||
* node bin/reset-password.mjs
|
||
* npx omniroute reset-password
|
||
*
|
||
* Resets the admin password for OmniRoute.
|
||
* Prompts for a new password and updates the database directly.
|
||
*
|
||
* @module bin/reset-password
|
||
*/
|
||
|
||
import { createInterface } from "node:readline";
|
||
import { resolveDataDir, resolveStoragePath } from "./cli/data-dir.mjs";
|
||
import { readManagementPasswordState, resetManagementPassword } from "./cli/sqlite.mjs";
|
||
|
||
// Resolve data directory — same logic as the server
|
||
const DATA_DIR = resolveDataDir();
|
||
const DB_PATH = resolveStoragePath(DATA_DIR);
|
||
|
||
const rl = createInterface({
|
||
input: process.stdin,
|
||
output: process.stdout,
|
||
});
|
||
|
||
function ask(question) {
|
||
return new Promise((resolve) => rl.question(question, resolve));
|
||
}
|
||
|
||
console.log("\n🔑 OmniRoute — Password Reset\n");
|
||
|
||
async function main() {
|
||
// Check if database exists
|
||
const passwordState = await readManagementPasswordState(DB_PATH);
|
||
if (!passwordState.exists) {
|
||
console.error(`❌ Database not found at: ${DB_PATH}`);
|
||
console.error(` Make sure OmniRoute has been started at least once.`);
|
||
console.error(` Or set DATA_DIR env var to your data directory.\n`);
|
||
process.exit(1);
|
||
}
|
||
|
||
if (passwordState.hasPassword) {
|
||
console.log("ℹ️ A password is currently set.");
|
||
} else {
|
||
console.log("ℹ️ No password is currently set.");
|
||
}
|
||
|
||
const password = await ask("Enter new password (min 8 chars): ");
|
||
|
||
if (!password || password.length < 8) {
|
||
console.error("\n❌ Password must be at least 8 characters.\n");
|
||
rl.close();
|
||
process.exit(1);
|
||
}
|
||
|
||
const confirm = await ask("Confirm new password: ");
|
||
|
||
if (password !== confirm) {
|
||
console.error("\n❌ Passwords do not match.\n");
|
||
rl.close();
|
||
process.exit(1);
|
||
}
|
||
|
||
await resetManagementPassword(password, DB_PATH);
|
||
rl.close();
|
||
|
||
console.log("\n✅ Password reset successfully!");
|
||
console.log(" Restart OmniRoute for changes to take effect.\n");
|
||
}
|
||
|
||
main().catch((err) => {
|
||
console.error(`\n❌ Error: ${err.message}\n`);
|
||
rl.close();
|
||
process.exit(1);
|
||
});
|