Browse Source

Implemented mechanism for setting the url, and video directories for the system.

pull/8/head
jrtechs 5 years ago
parent
commit
93f645dfad
8 changed files with 155 additions and 3 deletions
  1. +12
    -3
      configManager.js
  2. +3
    -0
      html/header.html
  3. +56
    -0
      html/system.html
  4. +2
    -0
      routes/index.js
  5. +32
    -0
      routes/system/index.js
  6. +20
    -0
      routes/system/indexVideos.js
  7. +22
    -0
      routes/system/updateSystem.js
  8. +8
    -0
      videoManager.js

+ 12
- 3
configManager.js View File

@ -17,17 +17,26 @@ module.exports=
getRootDirectory: function() getRootDirectory: function()
{ {
return "/home/jeff/public/Shows/Rick And Morty/Season 1";
return config.privateDir;
}, },
getPublicDirectory: function() getPublicDirectory: function()
{ {
return "/home/jeff/work/aaSchool/Algo/online Lectures/";
return config.publicDir;
}, },
getServerURL: function() 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();
} }
}; };

+ 3
- 0
html/header.html View File

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

+ 56
- 0
html/system.html View File

@ -0,0 +1,56 @@
<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">
</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">
</div>
</div>
</div>
</div>

+ 2
- 0
routes/index.js View File

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

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

@ -0,0 +1,32 @@
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");
function getSystemInformation(templateContext, request)
{
templateContext.serverURL = configLoader.getServerURL();
templateContext.privateDir = configLoader.getRootDirectory();
templateContext.publicDir = configLoader.getPublicDirectory();
}
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");
}
});
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.get('/', (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;

+ 8
- 0
videoManager.js View File

@ -121,5 +121,13 @@ module.exports =
} }
return false; return false;
} }
},
reIndexVideos: function()
{
publicVideos = [];
privateVideos = [];
module.exports.indexVideos(configManager.getPublicDirectory(), publicVideos, "public");
module.exports.indexVideos(configManager.getRootDirectory(), privateVideos, "public");
} }
}; };

Loading…
Cancel
Save