|
|
@@ -2,78 +2,27 @@ const fs = require("fs");
|
|
|
|
|
|
module.exports = {
|
|
|
listDirectories: function(req, res){
|
|
|
- // const searchDir = function(path, currentObject){
|
|
|
- // let response = fs.readdirSync(path);
|
|
|
-
|
|
|
- // for(let i = 0; i < response.length; i++){
|
|
|
- // let newPath = `${path}/${response[i]}`;
|
|
|
-
|
|
|
- // let newObject = ({
|
|
|
- // name: response[i].replace(/-/g, " "),
|
|
|
- // path: newPath.substring(newPath.indexOf("/travel") + 7, newPath.length),
|
|
|
- // contents: []
|
|
|
- // });
|
|
|
-
|
|
|
- // if(response[i].includes(".") === false){
|
|
|
- // currentObject.contents.push(newObject);
|
|
|
- // searchDir(newPath, newObject);
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- // return currentObject;
|
|
|
- // }
|
|
|
-
|
|
|
- // let result = searchDir(`${__dirname}/../content`, {
|
|
|
- // contents: []
|
|
|
- // });
|
|
|
-
|
|
|
- // let array = [];
|
|
|
- // for(let i = 0; i < result.contents.length; i++){
|
|
|
- // if(result.contents[i].name === "travel"){
|
|
|
- // array = result.contents[i].contents;
|
|
|
- // break;
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- // return res.json(array);
|
|
|
-
|
|
|
- let array = [];
|
|
|
-
|
|
|
let traverse = (dir)=>{
|
|
|
let contents = fs.readdirSync(dir);
|
|
|
|
|
|
- let newArray = [];
|
|
|
- let hasSubDir = false;
|
|
|
+ let array = [];
|
|
|
for(let i = 0; i < contents.length; i++){
|
|
|
if(contents[i].includes(".") === false){
|
|
|
- hasSubDir = true;
|
|
|
- let newPath = `${dir}/${contents[i]}`;
|
|
|
-
|
|
|
- newArray.push({
|
|
|
+ array.push({
|
|
|
name: contents[i],
|
|
|
- img: ""
|
|
|
+ contents: traverse(`${dir}/${contents[i]}`)
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ array.push({
|
|
|
+ src: `${dir.substring(dir.indexOf("/travel") + 7)}/${contents[i]}`
|
|
|
});
|
|
|
-
|
|
|
- let inner = fs.readdirSync(newPath);
|
|
|
- for(let i = 0; i < inner.length; i++){
|
|
|
- if(inner[i].includes(".jpg")){
|
|
|
- newArray.img = `${newPath}/${inner[i]}`;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- traverse(newPath);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(hasSubDir === false){
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- return newArray;
|
|
|
+ return array;
|
|
|
}
|
|
|
|
|
|
- let array = traverse(`${__dirname}/../content/travel`);
|
|
|
+ return res.json(traverse(`${__dirname}/../content/travel`));
|
|
|
},
|
|
|
|
|
|
getImages: function(req, res){
|