Browse Source

Updated videos to work with public and private sets.

pull/7/head
jrtechs 5 years ago
parent
commit
d52f0696e5
5 changed files with 139 additions and 58 deletions
  1. +1
    -1
      configManager.js
  2. +3
    -1
      routes/icon.js
  3. +7
    -2
      routes/video.js
  4. +3
    -54
      routes/videos.js
  5. +125
    -0
      videoManager.js

+ 1
- 1
configManager.js View File

@ -17,7 +17,7 @@ module.exports=
getRootDirectory: function() getRootDirectory: function()
{ {
return "/home/jeff/work/aaSchool/Algo/online Lectures/";
return "/home/jeff/public/Shows/Rick And Morty/Season 1";
}, },
getPublicDirectory: function() getPublicDirectory: function()

+ 3
- 1
routes/icon.js View File

@ -4,6 +4,8 @@ const utils = require("../utils");
const fs = require('fs'); const fs = require('fs');
const videoManager = require('../videoManager');
function isPublicVideo(videoURL) function isPublicVideo(videoURL)
{ {
return false; return false;
@ -22,7 +24,7 @@ routes.get('/', (request, result) =>
var file=""; var file="";
if(!isPublicVideo(videoID))
if(!videoManager.isPublicVideo(videoID))
{ {
if(utils.checkPrivilege(request) >= utils.PRIVILEGE.MEMBER) if(utils.checkPrivilege(request) >= utils.PRIVILEGE.MEMBER)
{ {

+ 7
- 2
routes/video.js View File

@ -8,14 +8,19 @@ const configManager = require("../configManager");
const fs = require('fs'); const fs = require('fs');
const videoManager = require("../videoManager");
routes.get('/', (request, result) => routes.get('/', (request, result) =>
{ {
var videoID = request.query.v;
if(utils.checkPrivilege(request) >= utils.PRIVILEGE.MEMBER || if(utils.checkPrivilege(request) >= utils.PRIVILEGE.MEMBER ||
userUtils.isValidAPI(request.query.api))
userUtils.isValidAPI(request.query.api) ||
videoManager.isPublicVideo(videoID))
{ {
const rootDir = configManager.getRootDirectory(); const rootDir = configManager.getRootDirectory();
var videoID = request.query.v;
const path = rootDir + videoID; const path = rootDir + videoID;
const stat = fs.statSync(path); const stat = fs.statSync(path);
const fileSize = stat.size; const fileSize = stat.size;

+ 3
- 54
routes/videos.js View File

@ -2,74 +2,23 @@ const routes = require('express').Router();
const utils = require("../utils"); const utils = require("../utils");
const recursive = require('../recursiveTraversal');
const configManager = require("../configManager");
const filepreview = require('filepreview');
const fs = require('fs');
var privateVideos = null;
var publicVideos = null;
function getVideosForTemplate(templateContext, rootDir, templateKey, videos)
{
if(videos === null)
{
videos = [];
return new Promise(function(resolve, reject)
{
recursive(rootDir, function (err, files)
{
console.log(files);
files.forEach(file =>
{
var splitArray = file.split('/');
var name = splitArray[splitArray.length -1];
const icon = 'img/' + templateKey + '/' + name + ".png";
if (!fs.existsSync(icon))
{
filepreview.generate(file, icon, function(error) {
if (error) {
return console.log(error);
}
console.log('File preview is located ' + icon);
});
}
videos.push({name: file.replace(rootDir, '')});
});
templateContext[templateKey] = videos;
resolve();
});
})
}
else
{
templateContext[templateKey] = videos;
}
}
const videoManager = require("../videoManager");
function getVideosTemplateInformation(templateContext, request) function getVideosTemplateInformation(templateContext, request)
{ {
var promises = []; var promises = [];
const rootDir = configManager.getRootDirectory();
const rootPublicDir = configManager.getPublicDirectory();
if(utils.checkPrivilege(request) >= utils.PRIVILEGE.MEMBER) if(utils.checkPrivilege(request) >= utils.PRIVILEGE.MEMBER)
{ {
promises.push(getVideosForTemplate(templateContext, rootDir, "private", privateVideos));
promises.push(videoManager.getVideosForTemplate(templateContext, "private"));
} }
else else
{ {
templateContext["private"] = []; templateContext["private"] = [];
} }
promises.push(getVideosForTemplate(templateContext, rootPublicDir, "public", publicVideos));
promises.push(videoManager.getVideosForTemplate(templateContext, "public"));
return Promise.all(promises); return Promise.all(promises);
} }

+ 125
- 0
videoManager.js View File

@ -0,0 +1,125 @@
const configManager = require('./configManager');
const recursive = require('./recursiveTraversal');
const filepreview = require('filepreview');
const fs = require('fs');
var privateVideos = null;
var publicVideos = null;
module.exports =
{
indexVideos: function(rootDir, videos, templateKey)
{
return new Promise(function(resolve, reject)
{
recursive(rootDir, function (err, files)
{
console.log(files);
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
};
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, '')});
});
resolve();
});
}).catch(function(error)
{
console.log(error);
})
},
getVideosForTemplate: function(templateContext, templateKey)
{
return new Promise(function(resolve, reject)
{
var videos, rootDir;
if(templateKey === "public")
{
videos = publicVideos;
rootDir = configManager.getPublicDirectory();
}
else
{
videos = privateVideos;
rootDir = configManager.getRootDirectory();
}
if(videos === null)
{
videos = [];
module.exports.indexVideos(rootDir, videos, templateKey)
.then(function()
{
templateContext[templateKey] = videos;
if(templateKey === "public")
publicVideos = videos;
else
privateVideos = videos;
resolve();
})
}
else
{
templateContext[templateKey] = videos;
resolve();
}
})
},
isPublicVideo: function(videoName)
{
if(publicVideos == null)
{
publicVideos = [];
rootDir = configManager.getPublicDirectory();
module.exports.indexVideos(rootDir, publicVideos, "public").then(function()
{
for(var i = 0; i < publicVideos.length; i++)
{
const splitArray = publicVideos[i].name.split('/');
const name = splitArray[splitArray.length -1];
if(name === videoName)
{
return true;
}
}
return false;
});
}
else
{
for(var i = 0; i < publicVideos.length; i++)
{
const splitArray = publicVideos[i].name.split('/');
const name = splitArray[splitArray.length -1];
if(name === videoName)
{
return true;
}
}
return false;
}
}
};

Loading…
Cancel
Save