Browse Source

Started implementing the system with express routes.

pull/6/head
Jeffery Russell 5 years ago
parent
commit
2314f8c836
14 changed files with 204 additions and 43 deletions
  1. +10
    -0
      routes/icon.js
  2. +33
    -0
      routes/index.js
  3. +10
    -0
      routes/users/addUser.js
  4. +10
    -0
      routes/users/edituser.js
  5. +10
    -0
      routes/users/index.js
  6. +10
    -0
      routes/users/login.js
  7. +10
    -0
      routes/users/logout.js
  8. +10
    -0
      routes/users/removeuser.js
  9. +10
    -0
      routes/users/revokeAPI.js
  10. +10
    -0
      routes/users/updateUser.js
  11. +10
    -0
      routes/video.js
  12. +11
    -0
      routes/videos.js
  13. +10
    -0
      routes/watch.js
  14. +50
    -43
      server.js

+ 10
- 0
routes/icon.js View File

@ -0,0 +1,10 @@
const routes = require('express').Router();
routes.get('/', (request, result) =>
{
});
module.exports = routes;

+ 33
- 0
routes/index.js View File

@ -0,0 +1,33 @@
const routes = require('express').Router();
const icon = require('./icon');
routes.get('/icon', icon);
const video = require('./video');
routes.get('/video', video);
const videos = require('./videos');
routes.get('/videos', videos);
const watch = require('./watch');
routes.get('/watch', watch);
const users = require('./users');
routes.get('/users', users);
const utils = require("../utils");
function getHomePageInformation(templateContext, request)
{
templateContext.username = request.session.username;
}
routes.get('/', (request, result) =>
{
utils.renderHTML(request, result, "home.html", getHomePageInformation)
});
module.exports = routes;

+ 10
- 0
routes/users/addUser.js View File

@ -0,0 +1,10 @@
const routes = require('express').Router();
routes.get('/', (request, result) =>
{
});
module.exports = routes;

+ 10
- 0
routes/users/edituser.js View File

@ -0,0 +1,10 @@
const routes = require('express').Router();
routes.get('/', (request, result) =>
{
});
module.exports = routes;

+ 10
- 0
routes/users/index.js View File

@ -0,0 +1,10 @@
const routes = require('express').Router();
const utils = require("../../utils");
routes.get('/', (request, result) =>
{
utils.renderHTML(request, result, "users.html", getUserInformation);
});
module.exports = routes;

+ 10
- 0
routes/users/login.js View File

@ -0,0 +1,10 @@
const routes = require('express').Router();
routes.get('/', (request, result) =>
{
});
module.exports = routes;

+ 10
- 0
routes/users/logout.js View File

@ -0,0 +1,10 @@
const routes = require('express').Router();
routes.get('/', (request, result) =>
{
});
module.exports = routes;

+ 10
- 0
routes/users/removeuser.js View File

@ -0,0 +1,10 @@
const routes = require('express').Router();
routes.get('/', (request, result) =>
{
});
module.exports = routes;

+ 10
- 0
routes/users/revokeAPI.js View File

@ -0,0 +1,10 @@
const routes = require('express').Router();
routes.get('/', (request, result) =>
{
});
module.exports = routes;

+ 10
- 0
routes/users/updateUser.js View File

@ -0,0 +1,10 @@
const routes = require('express').Router();
routes.get('/', (request, result) =>
{
});
module.exports = routes;

+ 10
- 0
routes/video.js View File

@ -0,0 +1,10 @@
const routes = require('express').Router();
routes.get('/', (request, result) =>
{
});
module.exports = routes;

+ 11
- 0
routes/videos.js View File

@ -0,0 +1,11 @@
const routes = require('express').Router();
const utils = require("../utils");
routes.get('/', (request, result) =>
{
utils.renderHTML(request, result, "videos.html", getVideosTemplateInformation)
});
module.exports = routes;

+ 10
- 0
routes/watch.js View File

@ -0,0 +1,10 @@
const routes = require('express').Router();
const utils = require("../utils");
routes.get('/', (request, result) =>
{
utils.renderHTML(req, res, "watch.html", getVideoTemplateInfo)
});
module.exports = routes;

+ 50
- 43
server.js View File

@ -14,8 +14,15 @@ const filepreview = require('filepreview');
const fs = require('fs');
const routes = require('./routes');
const app = express();
app.use('/', routes);
app.use(express.urlencoded());
app.use(express.json()); // if needed
@ -26,46 +33,46 @@ const config = fileIO.getFileAsJSON(CONFIG_FILE_NAME);
/**Initializes sessions for login */
app.use(session({ secret: config.sessionSecret, cookie: { maxAge: 6000000 }}));
/** Template engine */
const whiskers = require('whiskers');
// /** Template engine */
// const whiskers = require('whiskers');
var rootDir = '/home/jeff/work/aaSchool/Algo/online Lectures/';
var serverURL = "http://localhost:5000";
function fetchInTemplate(templateContext, templateKey, filename)
{
templateContext[templateKey] = fileIO.getFile(filename);
}
function renderHTML(request, result, templateFile, templateDependencyFunction)
{
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"));
if(checkPrivilege(request) >= PRIVILEGE.MEMBER)
{
templateContext.loggedIn = true;
if(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"));
}
Promise.all(prom).then(function(content)
{
result.write(whiskers.render(content[0], templateContext));
result.end();
});
}
// function fetchInTemplate(templateContext, templateKey, filename)
// {
// templateContext[templateKey] = fileIO.getFile(filename);
// }
// function renderHTML(request, result, templateFile, templateDependencyFunction)
// {
// 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"));
// if(checkPrivilege(request) >= PRIVILEGE.MEMBER)
// {
// templateContext.loggedIn = true;
// if(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"));
// }
//
// Promise.all(prom).then(function(content)
// {
// result.write(whiskers.render(content[0], templateContext));
// result.end();
// });
// }
function getUserInformation(templateContext, request)
{
@ -75,13 +82,13 @@ function getUserInformation(templateContext, request)
templateContext.username = request.session.username;
}
function getHomePageInformation(templateContext, request)
{
templateContext.username = request.session.username;
}
// function getHomePageInformation(templateContext, request)
// {
// templateContext.username = request.session.username;
// }
app.get('/', (req, res) => renderHTML(req, res, "home.html", getHomePageInformation));
app.get('/users', (req, res) => renderHTML(req, res, "users.html", getUserInformation));
// app.get('/', (req, res) => renderHTML(req, res, "home.html", getHomePageInformation));
// app.get('/users', (req, res) => renderHTML(req, res, "users.html", getUserInformation));
app.use(express.static('css'));
app.use(express.static('js'));
@ -135,8 +142,8 @@ function getVideoTemplateInfo(templateContext, request)
templateContext.videoURL = request.query.v.split(" ").join("%20");
}
app.get('/videos', (req, res) => renderHTML(req, res, "videos.html", getVideosTemplateInformation));
app.get('/watch', (req, res) => renderHTML(req, res, "watch.html", getVideoTemplateInfo));
// app.get('/videos', (req, res) => renderHTML(req, res, "videos.html", getVideosTemplateInformation));
// app.get('/watch', (req, res) => renderHTML(req, res, "watch.html", getVideoTemplateInfo));
function isPublicVideo(videoURL)

Loading…
Cancel
Save