From 17f8fd3500e179a6324840592b67b83b139ba746 Mon Sep 17 00:00:00 2001 From: Christopher Rose Date: Tue, 21 May 2019 10:38:54 +0530 Subject: [PATCH] Indexing basics --- index.js | 21 ++++++++++++++++++++- processing.js | 10 ++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 processing.js diff --git a/index.js b/index.js index 1c76d29..db6c6ff 100644 --- a/index.js +++ b/index.js @@ -3,15 +3,33 @@ const express = require('express') const bodyParser = require('body-parser') +const fs = require('fs') const path = require('path') +const processing = require('./processing') const port = 8080; app = express() -//const DIR=JSON.parse() +let settings = JSON.parse(fs.readFileSync("settings.json")) + +const DIR=settings.dirname; app.use(bodyParser.urlencoded({extended:false})) app.use(bodyParser.json()) +//Get the status of the folder and things related +app.get('/files',(req,res,next)=>{ + fs.readdir(DIR,(err,stream)=>{ + if(err){ + next(err) + } + else{ + + res.json({"filename":`${DIR}`,"rootdir":processing.dirprocess(stream,settings)}); + } + }) +}) + + //Attempt to upload a file app.put('/files/upload',(req,res)=>{ console.log("Upload attempted") @@ -22,6 +40,7 @@ app.post('/files/ls',(req,res)=>{ console.log("Request attempted") }) + app.get( '/*', express.static( path.join(__dirname,'static') ) ); app.all('*',(req,res)=>{ diff --git a/processing.js b/processing.js new file mode 100644 index 0000000..a1bc99e --- /dev/null +++ b/processing.js @@ -0,0 +1,10 @@ +module.exports.dirprocess = (dirstream,settings)=>{ + if(!settings.showHidden){ + let fdirstream = dirstream.filter((ele)=>{ + return ele[0]!='.' + }) + return fdirstream + } + else return dirstream +} +