Lightweight node app to use in place of plex to self host your video and movie collections. Running on just under 50MB of ram this is ideal for people looking to host videos on minimal hardware.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

83 lines
2.7 KiB

const fileIO = require('./fileIO');
function fetchInTemplate(templateContext, templateKey, filename)
{
templateContext[templateKey] = fileIO.getFile(filename);
}
const PRIVILEGE = {NOBODY: 0, MEMBER: 1, ADMIN: 2};
/** Template engine */
const whiskers = require('whiskers');
module.exports =
{
renderHTML: function(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(module.exports.checkPrivilege(request) >= PRIVILEGE.MEMBER)
{
templateContext.loggedIn = true;
if(module.exports.checkPrivilege(request) === PRIVILEGE.ADMIN)
templateContext.admin = true;
}
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));
result.end();
});
},
PRIVILEGE:
{
NOBODY: 0,
MEMBER: 1,
ADMIN: 2
},
checkPrivilege: function(request)
{
if(request.session.login !== true)
return module.exports.PRIVILEGE.NOBODY;
else if(request.session.admin === true)
return module.exports.PRIVILEGE.ADMIN;
return module.exports.PRIVILEGE.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"));
prom.push(fetchInTemplate(templateContext, "login","./html/login.html"));
templateContext.errorMessage = errorMessage;
Promise.all(prom).then(function(content)
{
result.write(whiskers.render(content[0], templateContext));
result.end();
});
}
};