From cf71e663dec6a0775f7b5d74ebeac24ca376523f Mon Sep 17 00:00:00 2001 From: knotteye Date: Mon, 25 Nov 2019 11:38:12 -0600 Subject: [PATCH] Handle temporary data from database better instead of modifying njkconf in place. --- src/http.ts | 22 +++++++++------------- templates/user.njk | 6 +++--- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/http.ts b/src/http.ts index 65e9f52..c049fba 100644 --- a/src/http.ts +++ b/src/http.ts @@ -39,37 +39,33 @@ async function init(satyr: any, port: number, ircconf: any){ }); app.get('/users', (req, res) => { db.query('select username from users').then((result) => { - njkconf.list = result; - res.render('list.njk', njkconf); - njkconf.list = ''; + res.render('list.njk', Object.assign({list: result}, njkconf)); }); }); app.get('/users/live', (req, res) => { db.query('select username,title from user_meta where live=1;').then((result) => { - njkconf.list = result; - res.render('live.njk', njkconf); - njkconf.list = ''; + res.render('live.njk', Object.assign({list: result}, njkconf)); }); }); app.get('/users/*', (req, res) => { db.query('select username,title,about from user_meta where username='+db.raw.escape(req.url.split('/')[2].toLowerCase())).then((result) => { if(result[0]){ - njkconf.user = result[0].username; + /*njkconf.user = result[0].username; njkconf.streamtitle = result[0].title; - njkconf.about = result[0].about; - res.render('user.njk', njkconf); + njkconf.about = result[0].about;*/ + res.render('user.njk', Object.assign(result[0], njkconf)); } else res.render('404.njk', njkconf); }); }); app.get('/vods/*', (req, res) => { njkconf.user = req.url.split('/')[2].toLowerCase(); - db.query('select username from user_meta where username='+db.raw.escape(njkconf.user)).then((result) => { + db.query('select username from user_meta where username='+db.raw.escape(req.url.split('/')[2].toLowerCase())).then((result) => { if(result[0]){ fs.readdir('./site/live/'+njkconf.user, {withFileTypes: true} , (err, files) => { - if(files) njkconf.list = files.filter(fn => fn.name.endsWith('.mp4')); - else njkconf.list = []; - res.render('vods.njk', njkconf); + //if(files) njkconf.list = files.filter(fn => fn.name.endsWith('.mp4')); + //else njkconf.list = []; + res.render('vods.njk', Object.assign({user: result[0].username, list: files.filter(fn => fn.name.endsWith('.mp4'))}, njkconf)); }); } else res.render('404.njk', njkconf); diff --git a/templates/user.njk b/templates/user.njk index ed13dbe..540089c 100644 --- a/templates/user.njk +++ b/templates/user.njk @@ -7,13 +7,13 @@ function newPopup(url) { }
- {{ user }} | {{ streamtitle | escape }} Links | Watch Chat VODs + {{ username }} | {{ title | escape }} Links | Watch Chat VODs
- +
@@ -32,7 +32,7 @@ function newPopup(url) { document.querySelector(".vjs-modal-dialog-content").textContent = "The stream is currently offline."; }); player.src({ - src: '/live/{{ user }}/index.mpd', + src: '/live/{{ username }}/index.mpd', type: 'application/dash+xml' }); })