From 9100f64d813900e1d2c03cd7057c426702c5a4fd Mon Sep 17 00:00:00 2001 From: Flummi Date: Mon, 16 May 2022 11:41:09 +0000 Subject: [PATCH 1/2] adduser --- debug/adduser.mjs | 35 +++++++++++++++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 debug/adduser.mjs diff --git a/debug/adduser.mjs b/debug/adduser.mjs new file mode 100644 index 0000000..271dedb --- /dev/null +++ b/debug/adduser.mjs @@ -0,0 +1,35 @@ +import db from '../src/inc/sql.mjs'; +import lib from '../src/inc/lib.mjs'; + +import readline from 'node:readline/promises'; +import stream from 'stream'; + +const _args = process.argv[2]; + +const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); + +const newuser = _args?.length ? _args : await rl.question('username: '); +const password = await rl.question('password: '); +const level = +(await rl.question('level (0-100): ')); + +rl.close(); + +if(!newuser.length || !password.length) { + console.log('nope lol'); + process.exit(); +} + +const id = (await db` + insert into "user" ${ + db({ + login: newuser.toLowerCase(), + user: newuser, + password: await lib.hash(password), + level: level >= 0 && level <= 100 ? level : 0 + }) + } + returning id +`)[0]?.id; + +console.log(`created new user ${newuser} with ID ${id}`); +process.exit(); diff --git a/package.json b/package.json index bab90eb..feaac8e 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "autotagger": "node --experimental-json-modules debug/autotagger.mjs", "thumbnailer": "node --experimental-json-modules debug/thumbnailer.mjs", "test": "node --experimental-json-modules debug/test.mjs", - "clean": "node --experimental-json-modules debug/clean.mjs" + "clean": "node --experimental-json-modules debug/clean.mjs", + "adduser": "node --experimental-json-modules debug/adduser.mjs" }, "author": "Flummi", "license": "MIT", From a7e2cb0dd93f3297a8f56ed6b29def0a9de1445b Mon Sep 17 00:00:00 2001 From: Flummi Date: Mon, 16 May 2022 12:57:13 +0000 Subject: [PATCH 2/2] psql-db: extension unaccent --- f0ck.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/f0ck.sql b/f0ck.sql index 81104de..85fd857 100644 --- a/f0ck.sql +++ b/f0ck.sql @@ -11,6 +11,7 @@ SET xmloption = content; SET client_min_messages = warning; SET row_security = off; +CREATE EXTENSION unaccent; CREATE FUNCTION public.delete_unused_tags() RETURNS trigger LANGUAGE plpgsql AS $$