fixing some problems and getting it ready

This commit is contained in:
2026-05-04 17:43:17 +02:00
parent ecbf909801
commit 4c4c11f574
5 changed files with 47 additions and 13 deletions

View File

@@ -1,3 +1,7 @@
# f0ckm
## prod
first things first things
`cp .env.example .env` `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/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 now vist http://localhost:1337 in your browser
## dev
tbd

View File

@@ -96,7 +96,9 @@ $DOCKER_COMPOSE down
$DOCKER_COMPOSE up -d $DOCKER_COMPOSE up -d
# Cleanup # Cleanup
echo "Cleaning up old docker resources..." # if you want to clear up all the old images uncomment
docker system prune -af # 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}" echo "Successfully updated ${TARGET} with tag ${TAG}"

View File

@@ -6,7 +6,8 @@ import { getDefaultLayout } from "../src/inc/settings.mjs";
const [username, password] = process.argv.slice(2); const [username, password] = process.argv.slice(2);
if (!username || !password) { 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); process.exit(1);
} }
@@ -20,14 +21,23 @@ async function createAdmin() {
// Check if user exists // Check if user exists
const existing = await db`select id from "user" where "login" = ${username.toLowerCase()} or "user" = ${username}`; 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 hash = await lib.hash(password);
const ts = ~~(Date.now() / 1e3); 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 { try {
const newUser = await db` const newUser = await db`
insert into "user" ("login", "password", "user", "created_at", "admin", "is_moderator", "activated") insert into "user" ("login", "password", "user", "created_at", "admin", "is_moderator", "activated")

View File

@@ -7,11 +7,12 @@
* node regen.mjs <id1> <id2> ... - Regenerate multiple items * node regen.mjs <id1> <id2> ... - Regenerate multiple items
* node regen.mjs --all - Regenerate ALL items * node regen.mjs --all - Regenerate ALL items
* node regen.mjs --audio - Regenerate all audio 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 db from "../src/inc/sql.mjs";
import queue from "./src/inc/queue.mjs"; import queue from "../src/inc/queue.mjs";
import cfg from "./src/inc/config.mjs"; import cfg from "../src/inc/config.mjs";
import fs from "fs/promises"; import fs from "fs/promises";
import path from "path"; 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 <id1> <id2> ... - Regenerate multiple items');
console.log(' node regen.mjs --all - Regenerate ALL 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 --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); process.exit(0);
} }
@@ -63,6 +66,12 @@ try {
} else if (args.includes('--audio')) { } 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`; 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`); 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 { } else {
const ids = args.map(Number).filter(n => !isNaN(n) && n > 0); const ids = args.map(Number).filter(n => !isNaN(n) && n > 0);
if (ids.length === 0) { if (ids.length === 0) {

View File

@@ -1,6 +1,7 @@
import _config from "../../config.json" with { type: "json" }; import _config from "../../config.json" with { type: "json" };
import path from "path"; import path from "path";
import fs from "fs"; import fs from "fs";
import { fileURLToPath } from "url";
let config = JSON.parse(JSON.stringify(_config)); let config = JSON.parse(JSON.stringify(_config));
@@ -14,7 +15,7 @@ if (process.env.NODE_ENV === 'production') {
config.main.development = false; 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 storage = process.env.STORAGE_DIR;
const resolvePath = (defaultRel) => { const resolvePath = (defaultRel) => {