Update module imports

This commit is contained in:
Cohee
2024-10-11 00:41:08 +03:00
parent a0e6030836
commit 0c8ccf1765
5 changed files with 58 additions and 39 deletions

View File

@ -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.');
}