Add a way to generate invites from the command line. Add database migration script.
parent
8caad60a43
commit
9605ff8c92
|
@ -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",
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
13
src/cli.ts
13
src/cli.ts
|
@ -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();
|
||||
|
||||
|
@ -24,3 +26,12 @@ if(flags.get('rmuser') !== ''){
|
|||
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();
|
||||
});
|
||||
}
|
|
@ -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 }
|
Reference in New Issue