1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
var walk = require('walk');
var fs = require('fs');
var path = require('path');
var configuration;
var files = [];
exports.start = function(config) {
configuration = config;
var walker = walk.walk(configuration.dir, { followLinks: false });
walker.on("directories", function (root, dirAr, next) {
var lastDir = path.join(__dirname, root).split('/');
if((lastDir.length - __dirname.split('/').length) < 2) {
dirAr.forEach(function(dir) {
files[dir.name] = { name: dir.name, template:
path.join(configuration.defaultSlides,
configuration.template) , slides: [] };
});
}
next();
}).on("file", function (root, fileStats, next) {
if(fileStats.name == configuration.description) {
next();
}
else if(fileStats.name == configuration.template) {
var lastDir = root.split('/');
files[lastDir[lastDir.length - 1]]['template'] = path.join(lastDir[lastDir.length - 1], fileStats.name);
next();
} else {
var lastDir = path.join(root).split('/');
if(files.hasOwnProperty(lastDir[lastDir.length - 1])) {
var ext = path.extname(fileStats.name);
var type = 'image';
switch (ext) {
case '.mp4':
case '.avi':
case '.ogv':
case '.mkv':
type = 'video';
break;
}
files[lastDir[lastDir.length - 1]]['slides'].push({ type: type, file: path.join(lastDir[lastDir.length - 1], fileStats.name), head: '', text: ''});
}
next();
}
}).on("errors", function (root, nodeStatsArray, next) {
next();
}).on("end", function () {
for(var slideset in files) {
if(!files.hasOwnProperty(slideset)) { continue; }
var data = fs.readFileSync(__dirname+'/'+configuration.dir+'/'+slideset+'/desc');
var descs = data.toString().split('\n');
for(var file in files[slideset]['slides']) {
if(!files[slideset]['slides'].hasOwnProperty(file)) { continue; }
if(!files[slideset]['slides'][file].hasOwnProperty('file')) { continue; }
for(var desc in descs) {
if(!descs.hasOwnProperty(desc)) { continue; }
var info = descs[desc].split('|');
var comp = files[slideset]['slides'][file]['file'].split('/');
if(info[0] === comp[comp.length - 1]) {
files[slideset]['slides'][file]['head'] = info[1];
files[slideset]['slides'][file]['text'] = info[2];
}
}
}
}
});
};
exports.getSlides = function(slideset, cb) {
for (var searchset in files) {
if(!files.hasOwnProperty(searchset)) { continue; }
if(files[searchset].name == slideset) {
cb(files[searchset]);
}
}
};
|