Browse Source

Merge pull request #8 from jrtechs/systemControls

System controls
pull/17/head
Jeffery Russell 5 years ago
committed by GitHub
parent
commit
0aac33d000
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 240 additions and 23 deletions
  1. +19
    -3
      configManager.js
  2. +3
    -0
      html/header.html
  3. +63
    -0
      html/system.html
  4. +2
    -2
      html/videos.html
  5. +2
    -0
      routes/index.js
  6. +42
    -0
      routes/system/index.js
  7. +20
    -0
      routes/system/indexVideos.js
  8. +22
    -0
      routes/system/updateSystem.js
  9. +4
    -0
      routes/user/index.js
  10. +63
    -18
      videoManager.js

+ 19
- 3
configManager.js View File

@ -17,17 +17,33 @@ module.exports=
getRootDirectory: function()
{
return "/home/jeff/public/Shows/Rick And Morty/Season 1";
return config.privateDir;
},
getPublicDirectory: function()
{
return "/home/jeff/work/aaSchool/Algo/online Lectures/";
return config.publicDir;
},
getServerURL: function()
{
return "http://localhost:5000";
return config.serverURL;
},
updateSystem: function(host, publicDir, privateDir)
{
config.serverURL = host;
config.privateDir = privateDir;
config.publicDir = publicDir;
module.exports.syncToDisk();
},
getUserCount: function()
{
return (config.hasOwnProperty('users')) ? config.users.length : 0;
}
};

+ 3
- 0
html/header.html View File

@ -40,6 +40,9 @@
<li class="nav-item">
<a class="nav-link" href="/user">Users</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/system">System</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/videos">Videos</a>
</li>

+ 63
- 0
html/system.html View File

@ -0,0 +1,63 @@
<center><h1>System Controls</h1></center>
<br>
<div class="row">
<div class="col-md-4 col-12">
<div class="card">
<div class="card-header">
<h3>System Status</h3>
</div>
<div class="card-body">
<p><b>Public Videos Indexed: </b>{publicVideoCount}</p>
<p><b>Private Videos Indexed: </b>{privateVideoCount}</p>
<p><b>Users: </b>{userCount}</p>
</div>
</div>
</div>
<div class="col-md-4 col-12">
<div class="card">
<div class="card-header">
<h3>Update System Settings</h3>
</div>
<div class="card-body">
<form action="/system/updateSystem" method ="post" class="p-2">
<div class="form-group">
<label> Base URL
<input class="form-control w-100" type="text" name="baseURL" value="{serverURL}" required>
</label>
</div>
<div class="form-group">
<label>Public Videos Directory
<input class="form-control w-100" type="text" name="publicDirectory" value="{publicDir}" required>
</label>
</div>
<div class="form-group">
<label>Private Videos Directory
<input class="form-control w-100" type="text" name="privateDirectory" value="{privateDir}">
</label>
</div>
<div class="text-center">
<input type="submit" name="add_user" value="Update System"
class="btn btn-lg btn-secondary"/>
</div>
</form>
</div>
</div>
</div>
<div class="col-md-4 col-12">
<div class="card">
<div class="card-header">
<h3>Re-Index Video</h3>
</div>
<div class="card-body">
<form action="/system/indexVideos" method ="post" class="p-2">
<div class="text-center">
<input type="submit" name="Index_Videos" value="Index Videos"
class="btn btn-lg btn-secondary"/>
</div>
</form>
</div>
</div>
</div>
</div>

+ 2
- 2
html/videos.html View File

@ -14,7 +14,7 @@
<div class="card-header">
<h4>{video.name}</h4>
</div>
<div class="card-body">
<div class="card-body w-100">
<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>
@ -23,7 +23,7 @@
</div>
{/for}
{for video in public}
<div class="col-md-3 videoElement p-2">
<div class="col-md-3 videoElement">
<div class="card">
<div class="card-header">
<h4>{video.name}</h4>

+ 2
- 0
routes/index.js View File

@ -15,6 +15,8 @@ routes.use('/watch', watch);
const user = require('./user');
routes.use('/user', user);
const syss = require('./system');
routes.use('/system', syss);
const utils = require("../utils");

+ 42
- 0
routes/system/index.js View File

@ -0,0 +1,42 @@
const routes = require('express').Router();
const utils = require("../../utils");
const indexVideos = require('./indexVideos');
routes.use('/indexVideos', indexVideos);
const updateSystem = require('./updateSystem');
routes.use('/updateSystem', updateSystem);
const configLoader = require("../../configManager");
const videoManager = require("../../videoManager");
function getSystemInformation(templateContext, request)
{
templateContext.serverURL = configLoader.getServerURL();
templateContext.privateDir = configLoader.getRootDirectory();
templateContext.publicDir = configLoader.getPublicDirectory();
templateContext.publicVideoCount = videoManager.getPublicVideoCount();
templateContext.privateVideoCount = videoManager.getPrivateVideoCount();
templateContext.userCount = configLoader.getUserCount();
}
routes.get('/', (request, result) =>
{
if(utils.checkPrivilege(request) >= utils.PRIVILEGE.ADMIN)
{
utils.renderHTML(request, result, "system.html", getSystemInformation);
}
else
{
utils.printError(result, "You need to be logged in");
}
});
routes.get('*', (request, result) =>
{
utils.printError(result, "Page not found.");
});
module.exports = routes;

+ 20
- 0
routes/system/indexVideos.js View File

@ -0,0 +1,20 @@
const routes = require('express').Router();
const utils = require("../../utils");
const videoManager = require("../../videoManager");
routes.post('/', (request, result) =>
{
if(utils.checkPrivilege(request) === utils.PRIVILEGE.ADMIN)
{
videoManager.reIndexVideos();
result.redirect('/system');
}
else
{
utils.printError(result, "You need to be logged in");
}
});
module.exports = routes;

+ 22
- 0
routes/system/updateSystem.js View File

@ -0,0 +1,22 @@
const routes = require('express').Router();
const utils = require("../../utils");
const configManager = require("../../configManager");
routes.post('/', (request, result) =>
{
if(utils.checkPrivilege(request) === utils.PRIVILEGE.ADMIN)
{
configManager.updateSystem(request.body.baseURL,
request.body.publicDirectory,
request.body.privateDirectory);
result.redirect('/system');
}
else
{
utils.printError(result, "You need to be logged in");
}
});
module.exports = routes;

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

@ -48,7 +48,11 @@ routes.get('/', (request, result) =>
{
utils.printError(result, "You need to be logged in");
}
});
routes.get('*', (request, result) =>
{
utils.printError(result, "Page not found.");
});
module.exports = routes;

+ 63
- 18
videoManager.js View File

@ -10,6 +10,49 @@ var privateVideos = null;
var publicVideos = null;
function createIndex(filename, videos, templateKey)
{
return new Promise(function(resolve, reject)
{
console.log("Generating icon for " + filename);
var splitArray = filename.split('/');
var name = splitArray[splitArray.length -1];
const icon = './icon/' + templateKey + '/' + name + ".png";
if (!fs.existsSync(icon))
{
var options = {
width: 200,
quality: 50,
previewTime: '00:05:00.000'
};
filepreview.generate(filename, icon, options, function (error)
{
if (error)
{
resolve();
}
console.log('File preview is located ' + icon);
resolve();
});
}
else
{
resolve();
}
})
}
async function runTasksSync(files, videos, templateKey)
{
for(var file of files)
{
await createIndex(file, videos, templateKey);
}
}
module.exports =
{
indexVideos: function(rootDir, videos, templateKey)
@ -20,26 +63,10 @@ module.exports =
{
files.forEach(file =>
{
var splitArray = file.split('/');
var name = splitArray[splitArray.length -1];
const icon = './icon/' + templateKey + '/' + name + ".png";
if (!fs.existsSync(icon))
{
var options = {
width: 200,
quality: 50,
previewTime: '00:05:00.000'
};
filepreview.generate(file, icon, options,function(error) {
if (error) {
return console.log(error);
}
console.log('File preview is located ' + icon);
});
}
videos.push({name: file.replace(rootDir, '')});
});
runTasksSync(files.splice(0, files.length/2), videos, templateKey);
runTasksSync(files.splice(files.length/2, files.length), videos, templateKey);
resolve();
});
}).catch(function(error)
@ -121,5 +148,23 @@ module.exports =
}
return false;
}
},
reIndexVideos: function()
{
publicVideos = [];
privateVideos = [];
module.exports.indexVideos(configManager.getPublicDirectory(), publicVideos, "public");
module.exports.indexVideos(configManager.getRootDirectory(), privateVideos, "private");
},
getPublicVideoCount: function()
{
return (publicVideos === null) ? 0: publicVideos.length;
},
getPrivateVideoCount: function()
{
return (privateVideos === null) ? 0: privateVideos.length;
}
};

Loading…
Cancel
Save