fixing some problems and getting it ready
This commit is contained in:
@@ -6,7 +6,8 @@ import { getDefaultLayout } from "../src/inc/settings.mjs";
|
||||
const [username, password] = process.argv.slice(2);
|
||||
|
||||
if (!username || !password) {
|
||||
console.error("Usage: node scripts/create-admin.mjs <username> <password>");
|
||||
console.error("Usage: node scripts/create-admin.mjs <username> '<password>'");
|
||||
console.error("Note: Wrap the password in single quotes to prevent your shell from interpreting special characters (like !).");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -20,14 +21,23 @@ async function createAdmin() {
|
||||
|
||||
// Check if user exists
|
||||
const existing = await db`select id from "user" where "login" = ${username.toLowerCase()} or "user" = ${username}`;
|
||||
if (existing.length > 0) {
|
||||
console.error("Error: Username already taken.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const hash = await lib.hash(password);
|
||||
const ts = ~~(Date.now() / 1e3);
|
||||
|
||||
if (existing.length > 0) {
|
||||
const userId = existing[0].id;
|
||||
console.log(`User already exists. Updating password and ensuring admin status for ID: ${userId}...`);
|
||||
|
||||
await db`
|
||||
update "user"
|
||||
set password = ${hash}, admin = true, is_moderator = true, activated = true
|
||||
where id = ${userId}
|
||||
`;
|
||||
|
||||
console.log(`--- Admin User ${username} Updated Successfully ---`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
try {
|
||||
const newUser = await db`
|
||||
insert into "user" ("login", "password", "user", "created_at", "admin", "is_moderator", "activated")
|
||||
|
||||
@@ -7,11 +7,12 @@
|
||||
* node regen.mjs <id1> <id2> ... - Regenerate multiple items
|
||||
* node regen.mjs --all - Regenerate ALL items
|
||||
* node regen.mjs --audio - Regenerate all audio items
|
||||
* node regen.mjs --pdf - Regenerate all PDF items
|
||||
*/
|
||||
|
||||
import db from "./src/inc/sql.mjs";
|
||||
import queue from "./src/inc/queue.mjs";
|
||||
import cfg from "./src/inc/config.mjs";
|
||||
import db from "../src/inc/sql.mjs";
|
||||
import queue from "../src/inc/queue.mjs";
|
||||
import cfg from "../src/inc/config.mjs";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
|
||||
@@ -23,6 +24,8 @@ if (args.length === 0) {
|
||||
console.log(' node regen.mjs <id1> <id2> ... - Regenerate multiple items');
|
||||
console.log(' node regen.mjs --all - Regenerate ALL items');
|
||||
console.log(' node regen.mjs --audio - Regenerate all audio items');
|
||||
console.log(' node regen.mjs --pdf - Regenerate all PDF items');
|
||||
console.log(' node regen.mjs --youtube - Regenerate all YouTube thumbnails');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
@@ -63,6 +66,12 @@ try {
|
||||
} else if (args.includes('--audio')) {
|
||||
items = await db`SELECT id, dest, mime, src FROM items WHERE active = true AND is_deleted = false AND mime ILIKE 'audio/%' ORDER BY id`;
|
||||
console.log(`Regenerating ${items.length} audio items...\n`);
|
||||
} else if (args.includes('--pdf')) {
|
||||
items = await db`SELECT id, dest, mime, src FROM items WHERE active = true AND is_deleted = false AND mime = 'application/pdf' ORDER BY id`;
|
||||
console.log(`Regenerating ${items.length} PDF items...\n`);
|
||||
} else if (args.includes('--youtube')) {
|
||||
items = await db`SELECT id, dest, mime, src FROM items WHERE active = true AND is_deleted = false AND mime = 'video/youtube' ORDER BY id`;
|
||||
console.log(`Regenerating ${items.length} YouTube items...\n`);
|
||||
} else {
|
||||
const ids = args.map(Number).filter(n => !isNaN(n) && n > 0);
|
||||
if (ids.length === 0) {
|
||||
Reference in New Issue
Block a user