diff --git a/README.md b/README.md index 4c1d4c4..8f06a8f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +# f0ckm + +## prod + first things `cp .env.example .env` @@ -28,6 +32,14 @@ host can either be localhost or the docker containers hostname, when running via `docker exec -t f0ckm node scripts/seed.mjs` -`docker exec -t f0ckm node scripts/create-admin.mjs admin [PASSWORD]` +`docker exec -t f0ckm node scripts/create-admin.mjs admin 'YOUR_PASSWORD_HERE'` + +For regular building after making changes to the source code + +`bash build.bash master` now vist http://localhost:1337 in your browser + +## dev + +tbd diff --git a/build.bash b/build.bash index e4b9516..03cc9aa 100644 --- a/build.bash +++ b/build.bash @@ -96,7 +96,9 @@ $DOCKER_COMPOSE down $DOCKER_COMPOSE up -d # Cleanup -echo "Cleaning up old docker resources..." -docker system prune -af +# if you want to clear up all the old images uncomment +# otherwise to prevent clutter clean it from time to time +#echo "Cleaning up old docker resources..." +#docker system prune -af echo "Successfully updated ${TARGET} with tag ${TAG}" diff --git a/scripts/create-admin.mjs b/scripts/create-admin.mjs index c93a547..8465dfa 100644 --- a/scripts/create-admin.mjs +++ b/scripts/create-admin.mjs @@ -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 "); + console.error("Usage: node scripts/create-admin.mjs ''"); + 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") diff --git a/scripts/recreate_thumbnail.mjs b/scripts/regen.mjs similarity index 78% rename from scripts/recreate_thumbnail.mjs rename to scripts/regen.mjs index ed20292..8321aaf 100644 --- a/scripts/recreate_thumbnail.mjs +++ b/scripts/regen.mjs @@ -7,11 +7,12 @@ * node regen.mjs ... - 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 ... - 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) { diff --git a/src/inc/config.mjs b/src/inc/config.mjs index 06ee746..7482c46 100644 --- a/src/inc/config.mjs +++ b/src/inc/config.mjs @@ -1,6 +1,7 @@ import _config from "../../config.json" with { type: "json" }; import path from "path"; import fs from "fs"; +import { fileURLToPath } from "url"; let config = JSON.parse(JSON.stringify(_config)); @@ -14,7 +15,7 @@ if (process.env.NODE_ENV === 'production') { config.main.development = false; } -const base = path.resolve(); +const base = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../"); const storage = process.env.STORAGE_DIR; const resolvePath = (defaultRel) => {