Indexing basics

This commit is contained in:
2019-05-21 10:38:54 +05:30
parent 265d18e403
commit 17f8fd3500
2 changed files with 30 additions and 1 deletions

View File

@@ -3,15 +3,33 @@
const express = require('express') const express = require('express')
const bodyParser = require('body-parser') const bodyParser = require('body-parser')
const fs = require('fs')
const path = require('path') const path = require('path')
const processing = require('./processing')
const port = 8080; const port = 8080;
app = express() 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.urlencoded({extended:false}))
app.use(bodyParser.json()) 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 //Attempt to upload a file
app.put('/files/upload',(req,res)=>{ app.put('/files/upload',(req,res)=>{
console.log("Upload attempted") console.log("Upload attempted")
@@ -22,6 +40,7 @@ app.post('/files/ls',(req,res)=>{
console.log("Request attempted") console.log("Request attempted")
}) })
app.get( '/*', express.static( path.join(__dirname,'static') ) ); app.get( '/*', express.static( path.join(__dirname,'static') ) );
app.all('*',(req,res)=>{ app.all('*',(req,res)=>{

10
processing.js Normal file
View File

@@ -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
}