Commit 8c00c022 authored by frankie's avatar frankie 💬

removal of nodejs folder

parent 8252d932
var fs = require('fs');
var http = require('http');
var browse = require("browse-directory");
var inventory_folder = 'sisyphus.inventory/';
var stored_data_keys = [];
var stored_data_values = [];
var stored_data = [];
var stored_last_retrieved = 0;
function recursive_retrieval( callback, _struct ) {
var i = stored_last_retrieved;
if ( i >= stored_data_keys.length ) {
populate( callback, _struct );
return;
}
var k = stored_data_keys[i];
stored_last_retrieved++;
if (
stored_data[k] &&
stored_data[k].src &&
!stored_data[k].data
) {
fs.readFile( stored_data[k].src, function(err, data) {
if (!err) {
var path = stored_data[k].src;
path = path.substring( path.indexOf('/')+2, path.length )
var txt = data.toString('utf8') + '|' + path;
stored_data[k].data = txt;
stored_data_values.push( txt );
}
recursive_retrieval( callback, _struct );
});
} else {
recursive_retrieval( callback, _struct );
}
}
function populate( callback, _struct ) {
_struct = stored_data_values.slice();
report( callback, _struct );
}
function extract_gallery( callback ) {
var files = browse.browseFiles(inventory_folder);
var rescan_required = -1;
for ( var i = 0; i < files.length; ++i ) {
var src = files[i].src;
if (
src === undefined ||
src.length < 2
) {
continue;
}
var found = false;
for ( var j in stored_data_keys ) {
if ( src == stored_data_keys[j] ) {
found = true;
}
}
if ( found ) {
continue;
}
stored_data[ src ] = {
'src': src,
'data': undefined
};
stored_data_keys = Object.keys( stored_data );
if ( rescan_required == -1 ) {
rescan_required = i;
}
}
var _struct = [];
if ( rescan_required != -1 ) {
recursive_retrieval( callback, _struct );
} else {
populate( callback, _struct );
}
}
function report( callback, _data ) {
if ( callback ) {
callback(_data);
}
}
http.createServer(function(req, res) {
extract_gallery( function (data) {
res.writeHead(200, {
// 'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Origin': 'http://sisyphus.technofle.sh',
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept',
'Content-Type': 'application/json'
});
res.end(JSON.stringify(data, null, 3));
} );
}).listen(3002, "127.0.0.1");
console.log('Gallery server running at http://127.0.0.1:3002/');
This diff is collapsed.