Browse Source

Updated videos page to display public videos to un-registered users.

pull/7/head
jrtechs 5 years ago
parent
commit
fa582405fa
15 changed files with 119 additions and 48 deletions
  1. +5
    -0
      configManager.js
  2. +4
    -0
      html/error.html
  3. +18
    -13
      html/home.html
  4. +1
    -6
      html/mainTemplate.html
  5. +15
    -1
      html/videos.html
  6. +5
    -6
      routes/icon.js
  7. +1
    -2
      routes/user/addUser.js
  8. +1
    -2
      routes/user/edituser.js
  9. +9
    -1
      routes/user/index.js
  10. +1
    -2
      routes/user/removeuser.js
  11. +4
    -0
      routes/user/revokeAPI.js
  12. +1
    -2
      routes/user/updateUser.js
  13. +1
    -3
      routes/video.js
  14. +31
    -7
      routes/videos.js
  15. +22
    -3
      utils.js

+ 5
- 0
configManager.js View File

@ -20,6 +20,11 @@ module.exports=
return "/home/jeff/work/aaSchool/Algo/online Lectures/";
},
getPublicDirectory: function()
{
return "/home/jeff/work/aaSchool/Algo/online Lectures/";
},
getServerURL: function()
{
return "http://localhost:5000";

+ 4
- 0
html/error.html View File

@ -0,0 +1,4 @@
<center><h1 class="align-content-center">{errorMessage}</h1></center>
<br><br>
<img class="mx-auto d-block" src="/404.jpg" alt="Page not found" width="40%" />
<br><br>

+ 18
- 13
html/home.html View File

@ -1,19 +1,24 @@
<div class="row">
<div class="col-4">
<div class="card">
<div class="card-header">
<h3>Profile</h3>
</div>
<div class="card-body">
<p>Welcome {username}.</p>
<br>
<form action="/user/logout" method ="post" class="p-2">
<div class="text-center">
<button class="btn btn-lg btn-secondary">LogOut</button>
</div>
{if loggedIn}
<div class="card">
<div class="card-header">
<h3>Profile</h3>
</div>
<div class="card-body">
<p>Welcome {username}.</p>
<br>
</form>
<form action="/user/logout" method ="post" class="p-2">
<div class="text-center">
<button class="btn btn-lg btn-secondary">LogOut</button>
</div>
<br>
</form>
</div>
</div>
</div>
{else}
{>login}
{/if}
</div>
</div>

+ 1
- 6
html/mainTemplate.html View File

@ -1,12 +1,7 @@
{>header}
<div class="container">
{if loggedIn}
{>main}
{else}
{>login}
{/if}
{>main}
</div>
{>footer}

+ 15
- 1
html/videos.html View File

@ -8,7 +8,21 @@
<br>
<div class="row">
{for video in videos}
{for video in private}
<div class="col-md-4 videoElement">
<div class="card">
<div class="card-header">
<h2>{video.name}</h2>
</div>
<div class="card-body">
<a href="/watch?v={video.name}" class="" role="button" aria-pressed="true">
<img src="/icon?v={video.name}" alt="Icon for {video.name}" width=100%/>
</a>
</div>
</div>
</div>
{/for}
{for video in public}
<div class="col-md-4 videoElement">
<div class="card">
<div class="card-header">

+ 5
- 6
routes/icon.js View File

@ -26,16 +26,17 @@ routes.get('/', (request, result) =>
{
if(utils.checkPrivilege(request) >= utils.PRIVILEGE.MEMBER)
{
file = fs.readFileSync("./img/private/" + name);
file = fs.readFileSync("./icon/private/" + name);
}
else
{
utils.printError(result, "You need to be logged in");
throw "Not logged in";
}
}
else
{
file = fs.readFileSync("./img/public/" + name);
file = fs.readFileSync("./icon/public/" + name);
}
result.writeHead(200, {'Content-Type': 'image/png',
@ -45,10 +46,8 @@ routes.get('/', (request, result) =>
}
catch(error)
{
result.writeHead(404, {'Content-Type': 'text/html',
'Vary': 'Accept-Encoding'});
result.write("Nada");
result.end();
utils.printError(result, "Invalid Icon");
console.log(error);
}
});

+ 1
- 2
routes/user/addUser.js View File

@ -17,8 +17,7 @@ routes.post('/', (request, result) =>
}
else
{
result.status(401);
result.send('None shall pass');
utils.printError(result, "You need to be logged in");
}
});

+ 1
- 2
routes/user/edituser.js View File

@ -17,8 +17,7 @@ routes.post('/', (request, result) =>
}
else
{
result.status(401);
result.send('None shall pass');
utils.printError(result, "You need to be logged in");
}
});

+ 9
- 1
routes/user/index.js View File

@ -40,7 +40,15 @@ function getUserInformation(templateContext, request)
routes.get('/', (request, result) =>
{
utils.renderHTML(request, result, "users.html", getUserInformation);
if(utils.checkPrivilege(request) >= utils.PRIVILEGE.MEMBER)
{
utils.renderHTML(request, result, "users.html", getUserInformation);
}
else
{
utils.printError(result, "You need to be logged in");
}
});
module.exports = routes;

+ 1
- 2
routes/user/removeuser.js View File

@ -13,8 +13,7 @@ routes.post('/', (request, result) =>
}
else
{
result.status(401);
result.send('None shall pass');
utils.printError(result, "You need to be logged in");
}
});

+ 4
- 0
routes/user/revokeAPI.js View File

@ -16,6 +16,10 @@ routes.post('/', (request, result) =>
userUtils.revokeAPI(request.session.username);
request.session.API = userUtils.getAPIKEY(request.session.username);
}
else
{
utils.printError(result, "You need to be logged in");
}
result.redirect('/user');
});

+ 1
- 2
routes/user/updateUser.js View File

@ -14,8 +14,7 @@ routes.post('/', (request, result) =>
}
else
{
result.status(401);
result.send('None shall pass');
utils.printError(result, "You need to be logged in");
}
});

+ 1
- 3
routes/video.js View File

@ -55,9 +55,7 @@ routes.get('/', (request, result) =>
}
else
{
console.log("invalid attempt to view video");
result.status(401);
result.send('None shall pass');
utils.printError(result, "You need to be logged in");
}
});

+ 31
- 7
routes/videos.js View File

@ -10,13 +10,14 @@ const filepreview = require('filepreview');
const fs = require('fs');
var videos = null;
var privateVideos = null;
function getVideosTemplateInformation(templateContext, request)
var publicVideos = null;
function getVideosForTemplate(templateContext, rootDir, templateKey, videos)
{
if(videos === null)
{
const rootDir = configManager.getRootDirectory();
videos = [];
return new Promise(function(resolve, reject)
{
@ -27,7 +28,7 @@ function getVideosTemplateInformation(templateContext, request)
{
var splitArray = file.split('/');
var name = splitArray[splitArray.length -1];
const icon = 'img/private/' + name + ".png";
const icon = 'img/' + templateKey + '/' + name + ".png";
if (!fs.existsSync(icon))
{
filepreview.generate(file, icon, function(error) {
@ -37,19 +38,42 @@ function getVideosTemplateInformation(templateContext, request)
console.log('File preview is located ' + icon);
});
}
videos.push({name: file.replace(rootDir, ''), length: "n/a"});
videos.push({name: file.replace(rootDir, '')});
});
templateContext.videos = videos;
templateContext[templateKey] = videos;
resolve();
});
})
}
else
{
templateContext.videos = videos;
templateContext[templateKey] = videos;
}
}
function getVideosTemplateInformation(templateContext, request)
{
var promises = [];
const rootDir = configManager.getRootDirectory();
const rootPublicDir = configManager.getPublicDirectory();
if(utils.checkPrivilege(request) >= utils.PRIVILEGE.MEMBER)
{
promises.push(getVideosForTemplate(templateContext, rootDir, "private", privateVideos));
}
else
{
templateContext["private"] = [];
}
promises.push(getVideosForTemplate(templateContext, rootPublicDir, "public", publicVideos));
return Promise.all(promises);
}
routes.get('/', (request, result) =>
{
utils.renderHTML(request, result, "videos.html", getVideosTemplateInformation)

+ 22
- 3
utils.js View File

@ -28,15 +28,16 @@ module.exports =
templateContext.loggedIn = true;
if(module.exports.checkPrivilege(request) === PRIVILEGE.ADMIN)
templateContext.admin = true;
if(templateDependencyFunction !== null)
prom.push(templateDependencyFunction(templateContext, request));
prom.push(fetchInTemplate(templateContext, "main","./html/" + templateFile));
}
else
{
prom.push(fetchInTemplate(templateContext, "login","./html/login.html"));
}
if(templateDependencyFunction !== null)
prom.push(templateDependencyFunction(templateContext, request));
prom.push(fetchInTemplate(templateContext, "main","./html/" + templateFile));
Promise.all(prom).then(function(content)
{
result.write(whiskers.render(content[0], templateContext));
@ -59,5 +60,23 @@ module.exports =
else if(request.session.admin === true)
return module.exports.PRIVILEGE.ADMIN;
return module.exports.RIVILEGE.MEMBER;
},
printError: function(result, errorMessage)
{
var templateContext = Object();
var prom = [];
prom.push(fileIO.getFile("./html/mainTemplate.html"));
prom.push(fetchInTemplate(templateContext, "header", "./html/header.html"));
prom.push(fetchInTemplate(templateContext, "footer", "./html/footer.html"));
prom.push(fetchInTemplate(templateContext, "main", "./html/error.html"));
templateContext.errorMessage = errorMessage;
Promise.all(prom).then(function(content)
{
result.write(whiskers.render(content[0], templateContext));
result.end();
});
}
};

Loading…
Cancel
Save