Commit 0361c765 by Amir Aharon

support subdirs

parent 2b7f3db1
Showing with 20 additions and 3 deletions
......@@ -56,7 +56,8 @@ app.get("/*", function(req,res){
});
function getCurrentPollingResp(path){
const jsonFile = jsonFilesMap[path];
let prefix = trimSuffix(path);
const jsonFile = jsonFilesMap[prefix];
if (jsonFile){
if (Array.isArray(jsonFile)){
return jsonFile.map(entity => getCurrentEntity(entity));
......@@ -145,6 +146,13 @@ function handleReadFile(filePath,filePrefix){
}
function trimSuffix(fileName){
let fileSuffixOffset = fileName.lastIndexOf('.');
let fileStartSuffix = 0;
let fileSuffix = fileSuffixOffset != -1 ? fileName.slice(fileStartSuffix,fileSuffixOffset) : fileName;
return fileSuffix;
}
function getFilePrefix(fileName){
let filePrefixOffset = fileName.lastIndexOf('.');
let fileStartPrefix = fileName.lastIndexOf('/');
......@@ -157,7 +165,7 @@ function getFilePrefix(fileName){
return filePrefix;
}
function handleReadDirectory(dirPath){
function handleReadDirectory(dirPath,dirPrefix){
fs.readdir(dirPath, function(err, items) {
console.log(items);
/**
......@@ -166,7 +174,16 @@ function handleReadDirectory(dirPath){
*/
items.forEach(item => {
let filePrefix = getFilePrefix(item);
handleReadFile(dirPath + '/' + item, filePrefix);
if (dirPrefix)
filePrefix = dirPrefix + '/' + filePrefix;
let itemPath = dirPath + '/' + item;
fs.stat(itemPath, (err, stats) => {
if (err) throw err;
if (stats.isFile())
handleReadFile(itemPath, filePrefix);
else
handleReadDirectory(itemPath,filePrefix);
});
});
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment