Browse Source

Implemented the indexing functionality for videos and icons.

pull/8/head
jrtechs 5 years ago
parent
commit
15d4f919e3
6 changed files with 64 additions and 23 deletions
  1. +6
    -1
      html/system.html
  2. +2
    -2
      html/videos.html
  3. +5
    -0
      routes/system/index.js
  4. +1
    -1
      routes/system/indexVideos.js
  5. +4
    -0
      routes/user/index.js
  6. +46
    -19
      videoManager.js

+ 6
- 1
html/system.html View File

@ -49,7 +49,12 @@
<h3>Re-Index Video</h3> <h3>Re-Index Video</h3>
</div> </div>
<div class="card-body"> <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>
</div> </div>

+ 2
- 2
html/videos.html View File

@ -14,7 +14,7 @@
<div class="card-header"> <div class="card-header">
<h4>{video.name}</h4> <h4>{video.name}</h4>
</div> </div>
<div class="card-body">
<div class="card-body w-100">
<a href="/watch?v={video.name}" class="" role="button" aria-pressed="true"> <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%/> <img src="/icon?v={video.name}" alt="Icon for {video.name}" width=100%/>
</a> </a>
@ -23,7 +23,7 @@
</div> </div>
{/for} {/for}
{for video in public} {for video in public}
<div class="col-md-3 videoElement p-2">
<div class="col-md-3 videoElement">
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
<h4>{video.name}</h4> <h4>{video.name}</h4>

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

@ -29,4 +29,9 @@ routes.get('/', (request, result) =>
} }
}); });
routes.get('*', (request, result) =>
{
utils.printError(result, "Page not found.");
});
module.exports = routes; module.exports = routes;

+ 1
- 1
routes/system/indexVideos.js View File

@ -4,7 +4,7 @@ const utils = require("../../utils");
const videoManager = require("../../videoManager"); const videoManager = require("../../videoManager");
routes.get('/', (request, result) =>
routes.post('/', (request, result) =>
{ {
if(utils.checkPrivilege(request) === utils.PRIVILEGE.ADMIN) if(utils.checkPrivilege(request) === utils.PRIVILEGE.ADMIN)
{ {

+ 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"); utils.printError(result, "You need to be logged in");
} }
});
routes.get('*', (request, result) =>
{
utils.printError(result, "Page not found.");
}); });
module.exports = routes; module.exports = routes;

+ 46
- 19
videoManager.js View File

@ -10,6 +10,49 @@ var privateVideos = null;
var publicVideos = 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 = module.exports =
{ {
indexVideos: function(rootDir, videos, templateKey) indexVideos: function(rootDir, videos, templateKey)
@ -20,26 +63,10 @@ module.exports =
{ {
files.forEach(file => 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, '')}); 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(); resolve();
}); });
}).catch(function(error) }).catch(function(error)
@ -128,6 +155,6 @@ module.exports =
publicVideos = []; publicVideos = [];
privateVideos = []; privateVideos = [];
module.exports.indexVideos(configManager.getPublicDirectory(), publicVideos, "public"); module.exports.indexVideos(configManager.getPublicDirectory(), publicVideos, "public");
module.exports.indexVideos(configManager.getRootDirectory(), privateVideos, "public");
module.exports.indexVideos(configManager.getRootDirectory(), privateVideos, "private");
} }
}; };

Loading…
Cancel
Save