Handle temporary data from database better instead of modifying njkconf in place.

merge-requests/5/head
knotteye 2019-11-25 11:38:12 -06:00
parent f7d9c78d09
commit cf71e663de
2 changed files with 12 additions and 16 deletions

View File

@ -39,37 +39,33 @@ async function init(satyr: any, port: number, ircconf: any){
}); });
app.get('/users', (req, res) => { app.get('/users', (req, res) => {
db.query('select username from users').then((result) => { db.query('select username from users').then((result) => {
njkconf.list = result; res.render('list.njk', Object.assign({list: result}, njkconf));
res.render('list.njk', njkconf);
njkconf.list = '';
}); });
}); });
app.get('/users/live', (req, res) => { app.get('/users/live', (req, res) => {
db.query('select username,title from user_meta where live=1;').then((result) => { db.query('select username,title from user_meta where live=1;').then((result) => {
njkconf.list = result; res.render('live.njk', Object.assign({list: result}, njkconf));
res.render('live.njk', njkconf);
njkconf.list = '';
}); });
}); });
app.get('/users/*', (req, res) => { 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) => { db.query('select username,title,about from user_meta where username='+db.raw.escape(req.url.split('/')[2].toLowerCase())).then((result) => {
if(result[0]){ if(result[0]){
njkconf.user = result[0].username; /*njkconf.user = result[0].username;
njkconf.streamtitle = result[0].title; njkconf.streamtitle = result[0].title;
njkconf.about = result[0].about; njkconf.about = result[0].about;*/
res.render('user.njk', njkconf); res.render('user.njk', Object.assign(result[0], njkconf));
} }
else res.render('404.njk', njkconf); else res.render('404.njk', njkconf);
}); });
}); });
app.get('/vods/*', (req, res) => { app.get('/vods/*', (req, res) => {
njkconf.user = req.url.split('/')[2].toLowerCase(); 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]){ if(result[0]){
fs.readdir('./site/live/'+njkconf.user, {withFileTypes: true} , (err, files) => { fs.readdir('./site/live/'+njkconf.user, {withFileTypes: true} , (err, files) => {
if(files) njkconf.list = files.filter(fn => fn.name.endsWith('.mp4')); //if(files) njkconf.list = files.filter(fn => fn.name.endsWith('.mp4'));
else njkconf.list = []; //else njkconf.list = [];
res.render('vods.njk', njkconf); 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); else res.render('404.njk', njkconf);

View File

@ -7,13 +7,13 @@ function newPopup(url) {
} }
</script> </script>
</br> </br>
<span style="float: left;font-size: large;"><a href="/live/{{ user }}/index.mpd">{{ user }}</a> | {{ streamtitle | escape }}</b></span><span style="float: right;font-size: large;"> Links | <a href="rtmp://{{ domain }}/live/{{ user }}">Watch</a> <a href="JavaScript:newPopup('/chat?room={{ user }}');">Chat</a> <a href="/vods/{{ user }}">VODs</a></span> <span style="float: left;font-size: large;"><a href="/live/{{ username }}/index.mpd">{{ username }}</a> | {{ title | escape }}</b></span><span style="float: right;font-size: large;"> Links | <a href="rtmp://{{ domain }}/live/{{ username }}">Watch</a> <a href="JavaScript:newPopup('/chat?room={{ username }}');">Chat</a> <a href="/vods/{{ username }}">VODs</a></span>
<div id="jscontainer"> <div id="jscontainer">
<div id="jschild" style="width: 70%;height: 100%;"> <div id="jschild" style="width: 70%;height: 100%;">
<video controls poster="/thumbnail.jpg" class="video-js vjs-default-skin" id="live-video" style="width:100%;height:100%;"></video> <video controls poster="/thumbnail.jpg" class="video-js vjs-default-skin" id="live-video" style="width:100%;height:100%;"></video>
</div> </div>
<div id="jschild" class="webchat" style="width: 30%;height: 100%;"> <div id="jschild" class="webchat" style="width: 30%;height: 100%;">
<iframe src="/chat?room={{ user }}" frameborder="0" style="width: 100%;height: 100%;"></iframe> <iframe src="/chat?room={{ username }}" frameborder="0" style="width: 100%;height: 100%;"></iframe>
</div> </div>
</div> </div>
<script>window.HELP_IMPROVE_VIDEOJS = false;</script> <script>window.HELP_IMPROVE_VIDEOJS = false;</script>
@ -32,7 +32,7 @@ function newPopup(url) {
document.querySelector(".vjs-modal-dialog-content").textContent = "The stream is currently offline."; document.querySelector(".vjs-modal-dialog-content").textContent = "The stream is currently offline.";
}); });
player.src({ player.src({
src: '/live/{{ user }}/index.mpd', src: '/live/{{ username }}/index.mpd',
type: 'application/dash+xml' type: 'application/dash+xml'
}); });
}) })