diff --git a/configManager.js b/configManager.js index df2500e..e920f1e 100644 --- a/configManager.js +++ b/configManager.js @@ -17,17 +17,26 @@ 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(); } }; \ No newline at end of file diff --git a/html/header.html b/html/header.html index a40c60a..9ca05a3 100644 --- a/html/header.html +++ b/html/header.html @@ -40,6 +40,9 @@ + diff --git a/html/system.html b/html/system.html new file mode 100644 index 0000000..9d462cb --- /dev/null +++ b/html/system.html @@ -0,0 +1,56 @@ +

System Controls

+
+
+
+
+
+

System Status

+
+
+ +
+
+
+ +
+
+
+

Update System Settings

+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+ +
+
+
+

Re-Index Video

+
+
+ +
+
+
+
\ No newline at end of file diff --git a/routes/index.js b/routes/index.js index 4d37cb6..4389ee8 100644 --- a/routes/index.js +++ b/routes/index.js @@ -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"); diff --git a/routes/system/index.js b/routes/system/index.js new file mode 100644 index 0000000..aeed099 --- /dev/null +++ b/routes/system/index.js @@ -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; \ No newline at end of file diff --git a/routes/system/indexVideos.js b/routes/system/indexVideos.js new file mode 100644 index 0000000..5a467e0 --- /dev/null +++ b/routes/system/indexVideos.js @@ -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; \ No newline at end of file diff --git a/routes/system/updateSystem.js b/routes/system/updateSystem.js new file mode 100644 index 0000000..a89a97c --- /dev/null +++ b/routes/system/updateSystem.js @@ -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; \ No newline at end of file diff --git a/videoManager.js b/videoManager.js index 37cf0b3..f1aac34 100644 --- a/videoManager.js +++ b/videoManager.js @@ -121,5 +121,13 @@ module.exports = } return false; } + }, + + reIndexVideos: function() + { + publicVideos = []; + privateVideos = []; + module.exports.indexVideos(configManager.getPublicDirectory(), publicVideos, "public"); + module.exports.indexVideos(configManager.getRootDirectory(), privateVideos, "public"); } }; \ No newline at end of file