mirror of
https://git.waldn.net/git/knotteye/satyr.git
synced 2025-12-22 01:32:17 +00:00
Added some api functions, an express server for the API and nunjucks
Added nunjucks templates for frontend pages.
This commit is contained in:
39
src/api.ts
Normal file
39
src/api.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import * as db from "./database"
|
||||
|
||||
var config: any;
|
||||
function init(conf: object){
|
||||
config = conf;
|
||||
}
|
||||
|
||||
async function register(name: string, password: string, streamer: boolean) {
|
||||
if(!config.registration){
|
||||
return {"error":"registration disabled"};
|
||||
}
|
||||
else {
|
||||
if(name.includes(';') || name.includes(' ')) return {"error":"illegal characters"};
|
||||
let s: boolean;
|
||||
if(streamer && config.streamKeys) s = true;
|
||||
else s = false;
|
||||
let r: boolean = await db.addUser(name, password, s, false);
|
||||
if(r) return {"success":""};
|
||||
else return {"error":""};
|
||||
}
|
||||
}
|
||||
|
||||
async function login(name: string, pass: string) {
|
||||
return await db.validatePassword(name, pass);
|
||||
}
|
||||
|
||||
async function users(num: number) {
|
||||
return await db.query('select username from users limit '+num);
|
||||
}
|
||||
|
||||
async function user(name: string) {
|
||||
|
||||
}
|
||||
|
||||
async function instance() {
|
||||
|
||||
}
|
||||
|
||||
export { init, register };
|
||||
Reference in New Issue
Block a user