Add API functionality for twitch mirror.

merge-requests/25/head
knotteye 2020-10-12 12:11:04 -05:00
parent 44cc3213ca
commit 98927bd7b8
2 changed files with 18 additions and 3 deletions

View File

@ -18,7 +18,7 @@ async function register(name: string, password: string, confirm: string): Promis
} }
async function update(fields: object): Promise<object>{ async function update(fields: object): Promise<object>{
if(!fields['title'] && !fields['bio'] && (fields['rec'] !== 'true' && fields['rec'] !== 'false')) return {"error":"no valid fields specified"}; if(!fields['title'] && !fields['bio'] && (fields['rec'] !== 'true' && fields['rec'] !== 'false') && (fields['twitch'] !== 'true' && fields['twitch'] !== 'false') && !fields['twitch_key']) return {"error":"no valid fields specified"};
let qs: string = ""; let qs: string = "";
let f: boolean = false; let f: boolean = false;
if(fields['title']) {qs += ' user_meta.title='+db.raw.escape(fields['title']);f = true;} if(fields['title']) {qs += ' user_meta.title='+db.raw.escape(fields['title']);f = true;}
@ -30,8 +30,19 @@ async function update(fields: object): Promise<object>{
if(typeof(fields['rec']) === 'boolean' || typeof(fields['rec']) === 'number') { if(typeof(fields['rec']) === 'boolean' || typeof(fields['rec']) === 'number') {
if(f) qs+=','; if(f) qs+=',';
qs += ' users.record_flag='+db.raw.escape(fields['rec']); qs += ' users.record_flag='+db.raw.escape(fields['rec']);
f=true;
} }
await db.query('UPDATE users,user_meta SET'+qs+' WHERE users.username='+db.raw.escape(fields['name'])+' AND user_meta.username='+db.raw.escape(fields['name'])); if(typeof(fields['twitch']) === 'boolean' || typeof(fields['twitch']) === 'number') {
if(f) qs+=',';
qs += ' twitch_mirror.enabled='+db.raw.escape(fields['twitch']);
f=true;
}
if(fields['twitch_key']){
if(f) qs+=',';
qs += ' twitch_mirror.twitch_key='+db.raw.escape(fields['twitch_key']);
f = true;
}
await db.query('UPDATE users,user_meta,twitch_mirror SET'+qs+' WHERE users.username='+db.raw.escape(fields['name'])+' AND user_meta.username='+db.raw.escape(fields['name'])+' AND twitch_mirror.username='+db.raw.escape(fields['name']));
return {success:""}; return {success:""};
} }

View File

@ -238,10 +238,14 @@ async function initAPI() {
if(t) { if(t) {
if(req.body.record === "true") req.body.record = true; if(req.body.record === "true") req.body.record = true;
else if(req.body.record === "false") req.body.record = false; else if(req.body.record === "false") req.body.record = false;
if(req.body.twitch === "true") req.body.twitch = true;
else if(req.body.twitch === "false") req.body.twitch = false;
return api.update({name: t['username'], return api.update({name: t['username'],
title: "title" in req.body ? req.body.title : false, title: "title" in req.body ? req.body.title : false,
bio: "bio" in req.body ? req.body.bio : false, bio: "bio" in req.body ? req.body.bio : false,
rec: "record" in req.body ? req.body.record : "NA" rec: "record" in req.body ? req.body.record : "NA",
twitch: "twitch" in req.body ? req.body.twitch: "NA",
twitch_key: "twitch_key" in req.body ? req.body.twitch_key : false
}).then((r) => { }).then((r) => {
res.json(r); res.json(r);
return; return;