Handle temporary data from database better instead of modifying njkconf in place.
parent
f7d9c78d09
commit
cf71e663de
22
src/http.ts
22
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);
|
||||
|
|
|
@ -7,13 +7,13 @@ function newPopup(url) {
|
|||
}
|
||||
</script>
|
||||
</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="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>
|
||||
</div>
|
||||
<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>
|
||||
<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.";
|
||||
});
|
||||
player.src({
|
||||
src: '/live/{{ user }}/index.mpd',
|
||||
src: '/live/{{ username }}/index.mpd',
|
||||
type: 'application/dash+xml'
|
||||
});
|
||||
})
|
||||
|
|
Reference in New Issue