mirror of
https://git.waldn.net/git/knotteye/satyr.git
synced 2025-10-20 19:08:52 +00:00
Add a way to generate invites from the command line. Add database migration script.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
8
src/db/2.ts
Normal 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 }
|
Reference in New Issue
Block a user