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