Add a way to generate invites from the command line. Add database migration script.

merge-requests/26/head
knotteye 2020-10-13 15:48:39 -05:00
parent 8caad60a43
commit 9605ff8c92
4 changed files with 25 additions and 5 deletions

View File

@ -6,9 +6,10 @@
"author": "knotteye",
"scripts": {
"start": "ts-node src/index.ts",
"user": "ts-node src/cli.ts",
"cli": "ts-node src/cli.ts",
"setup": "sh install/setup.sh",
"migrate": "ts-node src/migrate.ts"
"migrate": "ts-node src/migrate.ts",
"invite": "ts-node src/cli.ts --invite"
},
"repository": {
"type": "git",

View File

@ -98,9 +98,9 @@ async function getConfig(username: string, all?: boolean): Promise<object>{
return t;
}
async function genInvite(user: string): Promise<string>{
async function genInvite(): Promise<string>{
var invitecode: string = base64id.generateId();
await db.query('INSERT INTO invites (code) VALUES ('+invitecode+')');
await db.query('INSERT INTO invites (code) VALUES (\"'+invitecode+'\")');
return invitecode;
}

View File

@ -1,4 +1,5 @@
import * as db from "./database"
import * as db from "./database";
import * as api from "./api";
import * as flags from "flags";
db.init();
@ -6,6 +7,7 @@ db.init();
flags.defineString('adduser', '', 'User to add');
flags.defineString('rmuser', '', 'User to remove');
flags.defineString('password', '', 'password to hash');
flags.defineBoolean('invite', false, 'generate invite code');
flags.parse();
@ -23,4 +25,13 @@ if(flags.get('rmuser') !== ''){
else console.log("Could not remove user.");
process.exit();
});
}
if(flags.get('invite')){
var config = require("./config").config;
api.genInvite().then((r: string) => {
console.log('invite code: '+r);
console.log('Direct the user to https://'+config['satyr']['domain']+'/invite/'+r);
process.exit();
});
}

8
src/db/2.ts Normal file
View File

@ -0,0 +1,8 @@
import * as db from "../database";
async function run () {
await db.query('CREATE TABLE IF NOT EXISTS invites(code VARCHAR(150))');
await db.query('INSERT INTO db_meta (version) VALUES (2)');
}
export { run }