Browse Source

Added functionality to view a video by using the user's api key.

pull/6/head
jrtechs 5 years ago
parent
commit
230306717a
3 changed files with 60 additions and 24 deletions
  1. +25
    -6
      html/watch.html
  2. +23
    -18
      server.js
  3. +12
    -0
      user.js

+ 25
- 6
html/watch.html View File

@ -1,13 +1,32 @@
<video id="videoPlayer" width="768" height="432" controls onerror="failed(event)">
<source src="/video?v={videoURL}" type="video/mp4">
Your browser does not support the video tag.
</video>
<h2 class="d-flex justify-content-center">{videoURL}</h2>
<div class="d-flex justify-content-center p-4">
<video id="videoPlayer" width="768" height="432" controls onerror="failed(event)">
<source src="/video?v={videoURL}" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
<div class="d-flex justify-content-center p-4">
<p id="copyStatus"></p>
<input class="form-control" type="text" value="{serverURL}/video?v={videoURL}&api={api}" id="directLink">
<button class="btn btn-secondary align-content-center" onclick="copyVideoPath()">Copy Direct Link</button>
</div>
<script>
function failed(e) {
function copyVideoPath()
{
var copyText = document.getElementById("directLink");
copyText.select();
document.execCommand("copy");
$("#copyStatus").html("URL copied to clipboard.");
}
function failed(e)
{
// video playback failed - show a message saying why
switch (e.target.error.code) {
switch (e.target.error.code)
{
case e.target.error.MEDIA_ERR_ABORTED:
alert('You aborted the video playback.');
break;

+ 23
- 18
server.js View File

@ -29,6 +29,8 @@ const whiskers = require('whiskers');
var rootDir = '/home/jeff/public/Shows/';
var serverURL = "localhost:5000";
function fetchInTemplate(templateContext, templateKey, filename)
{
templateContext[templateKey] = fileIO.getFile(filename);
@ -66,7 +68,6 @@ function renderHTML(request, result, templateFile, templateDependencyFunction)
function getUserInformation(templateContext, request)
{
templateContext.users = config.users;
templateContext.apiKey = request.session.API;
templateContext.id = request.session.userID;
templateContext.username = request.session.username;
@ -85,21 +86,6 @@ app.use(express.static('js'));
app.use(express.static('img'));
app.post('/login', function(request, result)
{
if(userUtils.checkLogin(request.body.username, request.body.password, config))
{
request.session.login = true;
request.session.username = request.body.username;
request.session.userID = userUtils.getID(request.body.username, config);
request.session.API = userUtils.getAPIKEY(request.body.username, config);
if(userUtils.isAdmin(request.body.username, config))
{
request.session.admin = true;
}
}
result.redirect('/');
});
var videos = null;
@ -130,6 +116,8 @@ function getVideosTemplateInformation(templateContext, request)
function getVideoTemplateInfo(templateContext, request)
{
templateContext.api = request.session.API;
templateContext.serverURL = serverURL;
templateContext.videoURL = request.query.v;
}
@ -139,11 +127,10 @@ app.get('/watch', (req, res) => renderHTML(req, res, "watch.html", getVideoTempl
app.get('/video/', function(request, result)
{
if(checkPrivilege(request) >= PRIVILEGE.MEMBER)
if(checkPrivilege(request) >= PRIVILEGE.MEMBER || userUtils.isValidAPI(request.query.api, config))
{
var videoID = request.query.v;
const path = rootDir + videoID;
const stat = fs.statSync(path);
const fileSize = stat.size;
const range = request.headers.range;
@ -295,4 +282,22 @@ app.post('/logout', function(request, result)
});
app.post('/login', function(request, result)
{
if(userUtils.checkLogin(request.body.username, request.body.password, config))
{
request.session.login = true;
request.session.username = request.body.username;
request.session.userID = userUtils.getID(request.body.username, config);
request.session.API = userUtils.getAPIKEY(request.body.username, config);
if(userUtils.isAdmin(request.body.username, config))
{
request.session.admin = true;
}
}
result.redirect('/');
});
app.listen(config.port, () => console.log(`App listening on port ${config.port}!`));

+ 12
- 0
user.js View File

@ -71,6 +71,18 @@ const getIndexOfUser = function(username, configuration)
module.exports =
{
isValidAPI: function(apiKey, configuration)
{
for(var i = 0; i < configuration.users.length; i++)
{
if(configuration.users[i].api === apiKey)
{
return true;
}
}
return false;
},
isAdmin: function(username, configuration)
{
var index = getIndexOfUser(username, configuration);

Loading…
Cancel
Save