mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Update module imports
This commit is contained in:
19
recover.js
19
recover.js
@ -1,7 +1,12 @@
|
||||
import fs from 'node:fs';
|
||||
import yaml from 'yaml';
|
||||
import storage from 'node-persist';
|
||||
import * as users from './src/users.js';
|
||||
import {
|
||||
initUserStorage,
|
||||
getPasswordSalt,
|
||||
getPasswordHash,
|
||||
toKey,
|
||||
} from './src/users.js';
|
||||
|
||||
const userAccount = process.argv[2];
|
||||
const userPassword = process.argv[3];
|
||||
@ -22,7 +27,7 @@ async function initStorage() {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await users.initUserStorage(dataRoot);
|
||||
await initUserStorage(dataRoot);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
@ -31,22 +36,22 @@ async function main() {
|
||||
/**
|
||||
* @type {import('./src/users').User}
|
||||
*/
|
||||
const user = await storage.get(users.toKey(userAccount));
|
||||
const user = await storage.get(toKey(userAccount));
|
||||
|
||||
if (!user) {
|
||||
console.error(`User "${userAccount}" not found.`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!user.enabled) {
|
||||
if (!user.enabled) {
|
||||
console.log('User is disabled. Enabling...');
|
||||
user.enabled = true;
|
||||
}
|
||||
|
||||
if (userPassword) {
|
||||
console.log('Setting new password...');
|
||||
const salt = users.getPasswordSalt();
|
||||
const passwordHash = users.getPasswordHash(userPassword, salt);
|
||||
const salt = getPasswordSalt();
|
||||
const passwordHash = getPasswordHash(userPassword, salt);
|
||||
user.password = passwordHash;
|
||||
user.salt = salt;
|
||||
} else {
|
||||
@ -55,7 +60,7 @@ async function main() {
|
||||
user.salt = '';
|
||||
}
|
||||
|
||||
await storage.setItem(users.toKey(userAccount), user);
|
||||
await storage.setItem(toKey(userAccount), user);
|
||||
console.log('User recovered. A program will exit now.');
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user