From 15d4f919e3fce9b24988ae363d87e8e8efa8a8ac Mon Sep 17 00:00:00 2001 From: jrtechs Date: Sun, 10 Feb 2019 08:52:58 -0500 Subject: [PATCH] Implemented the indexing functionality for videos and icons. --- html/system.html | 7 +++- html/videos.html | 4 +-- routes/system/index.js | 5 +++ routes/system/indexVideos.js | 2 +- routes/user/index.js | 4 +++ videoManager.js | 65 +++++++++++++++++++++++++----------- 6 files changed, 64 insertions(+), 23 deletions(-) diff --git a/html/system.html b/html/system.html index 9d462cb..b82c61e 100644 --- a/html/system.html +++ b/html/system.html @@ -49,7 +49,12 @@

Re-Index Video

- +
+
+ +
+
diff --git a/html/videos.html b/html/videos.html index 6ef6dcf..3c20dd0 100644 --- a/html/videos.html +++ b/html/videos.html @@ -14,7 +14,7 @@

{video.name}

-
+
Icon for {video.name} @@ -23,7 +23,7 @@
{/for} {for video in public} -
+

{video.name}

diff --git a/routes/system/index.js b/routes/system/index.js index aeed099..e89d8f7 100644 --- a/routes/system/index.js +++ b/routes/system/index.js @@ -29,4 +29,9 @@ routes.get('/', (request, result) => } }); +routes.get('*', (request, result) => +{ + utils.printError(result, "Page not found."); +}); + module.exports = routes; \ No newline at end of file diff --git a/routes/system/indexVideos.js b/routes/system/indexVideos.js index 5a467e0..468ebba 100644 --- a/routes/system/indexVideos.js +++ b/routes/system/indexVideos.js @@ -4,7 +4,7 @@ const utils = require("../../utils"); const videoManager = require("../../videoManager"); -routes.get('/', (request, result) => +routes.post('/', (request, result) => { if(utils.checkPrivilege(request) === utils.PRIVILEGE.ADMIN) { diff --git a/routes/user/index.js b/routes/user/index.js index 64b5ea4..55a073c 100644 --- a/routes/user/index.js +++ b/routes/user/index.js @@ -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; \ No newline at end of file diff --git a/videoManager.js b/videoManager.js index f1aac34..f4e365a 100644 --- a/videoManager.js +++ b/videoManager.js @@ -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) @@ -128,6 +155,6 @@ module.exports = publicVideos = []; privateVideos = []; module.exports.indexVideos(configManager.getPublicDirectory(), publicVideos, "public"); - module.exports.indexVideos(configManager.getRootDirectory(), privateVideos, "public"); + module.exports.indexVideos(configManager.getRootDirectory(), privateVideos, "private"); } }; \ No newline at end of file