Process file type and send it over
This commit is contained in:
9
index.js
9
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)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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{
|
||||
|
@@ -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(`<tr><td>null</td><td class="file-handlers"></td></tr>`)
|
||||
else
|
||||
contents.contents.forEach(element => {
|
||||
$('#files-table').append(`<tr><td class="file-name ${(element.type?'file-isDir':'file-isFile')}">${element.name}</td><td class="file-handlers"></td></tr>`)
|
||||
});
|
||||
}
|
||||
|
||||
//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();
|
||||
})
|
||||
|
@@ -10,7 +10,7 @@
|
||||
<body>
|
||||
<div class="navbar-container box-shadow-1">
|
||||
<div class="navbar">
|
||||
<div class="navbar-text">TEXT</div>
|
||||
<div class="navbar-text">Location: /<span id="files-location"></span></div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -23,15 +23,15 @@
|
||||
<td>Actions</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<tbody id="files-table">
|
||||
<!--<tr>
|
||||
<td>TEST1</td>
|
||||
<td class="file-handlers">TEST2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>TEST3</td>
|
||||
<td class="file-handlers">TEST4</td>
|
||||
</tr>
|
||||
</tr>-->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user