From 51775c76f2576b084272ddb250b1ff89f4225c34 Mon Sep 17 00:00:00 2001 From: Christopher Rose Date: Tue, 21 May 2019 20:31:41 +0530 Subject: [PATCH] Process file type and send it over --- index.js | 9 +++++---- processing.js | 6 +++++- static/base.css | 6 ++++++ static/base.js | 29 +++++++++++++++++++++++++++-- static/index.html | 8 ++++---- 5 files changed, 47 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 5821677..d82626f 100644 --- a/index.js +++ b/index.js @@ -18,12 +18,13 @@ app.use(bodyParser.json()) //Get the status of the folder and things related app.get('/files',(req,res,next)=>{ - fs.readdir(DIR,(err,stream)=>{ + fs.readdir(DIR,{withFileTypes:true},(err,stream)=>{ if(err){ next(err) } else{ - res.json({"filename":`${DIR}`,"rootdir":processing.dirprocess(stream,settings)}); + //res.json(stream[0].isDirectory()) + res.json({"filename":`${DIR}`,"loc":processing.dirprocess(stream,settings)}); } }) }) @@ -39,14 +40,14 @@ app.put('/files/upload',(req,res)=>{ //Get folder details app.post('/files/ls',(req,res,next)=>{ const location = processing.mergedir(req.body.loc,settings) - fs.readdir(location,(err,files)=>{ + fs.readdir(location,{withFileTypes:true},(err,files)=>{ if(err){ next(err) } else{ res.json({ "location": location , - "contents":files + "contents":processing.dirprocess(files,settings) }) } }) diff --git a/processing.js b/processing.js index 30ebafa..ffe1b99 100644 --- a/processing.js +++ b/processing.js @@ -4,9 +4,13 @@ module.exports.mergedir = (dirname,settings)=>{ } module.exports.dirprocess = (dirstream,settings)=>{ + dirstream.forEach(element => { + element.type = element.isDirectory() + }); if(!settings.showHidden){ let fdirstream = dirstream.filter((ele)=>{ - return ele[0]!='.' + //ele.type=ele.isDirectory + return ele.name[0]!='.' }) return fdirstream } diff --git a/static/base.css b/static/base.css index b0f8b71..23b4da3 100644 --- a/static/base.css +++ b/static/base.css @@ -98,6 +98,12 @@ table td{ tbody tr:last-child{ border:0; } +tbody td.file-isDir{ + font-style: italic; +} +tbody td.file-isDir::after{ + content: '/'; +} .box-shadow-1{ diff --git a/static/base.js b/static/base.js index 689b972..79f7e3b 100644 --- a/static/base.js +++ b/static/base.js @@ -1,8 +1,33 @@ -let currDir = '/'; +let currDir = {'loc':'','contents':null}; +function updateContents(contents){ + console.log(contents) + $('#files-location').html(contents.loc) + if(contents===null) $('#files-table').append(`null`) + else + contents.contents.forEach(element => { + $('#files-table').append(`${element.name}`) + }); +} //set table details -function setList(){ +function populateContents(){ + $.ajax('/files/ls'+currDir.loc,{ + method:'post', + data: currDir, + success:(msg)=>{ + updateContents(msg) + } + }) + return null; } + + + + +$(document).ready(()=>{ + populateContents(); + //updateContents(); +}) diff --git a/static/index.html b/static/index.html index 3667ca9..aa5471a 100644 --- a/static/index.html +++ b/static/index.html @@ -10,7 +10,7 @@ @@ -23,15 +23,15 @@ Actions - - + +