Files
nodejs-fm/index.js

54 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-05-19 18:48:50 +05:30
2019-05-19 12:21:40 +05:30
const express = require('express')
const bodyParser = require('body-parser')
2019-05-21 10:38:54 +05:30
const fs = require('fs')
2019-05-19 18:48:50 +05:30
const path = require('path')
2019-05-21 10:38:54 +05:30
const processing = require('./processing')
2019-05-19 18:48:50 +05:30
2019-05-19 12:21:40 +05:30
const port = 8080;
app = express()
2019-05-21 10:38:54 +05:30
let settings = JSON.parse(fs.readFileSync("settings.json"))
const DIR=settings.dirname;
2019-05-19 12:21:40 +05:30
app.use(bodyParser.urlencoded({extended:false}))
app.use(bodyParser.json())
2019-05-21 10:38:54 +05:30
//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)});
}
})
})
2019-05-19 13:08:23 +05:30
//Attempt to upload a file
app.put('/files/upload',(req,res)=>{
console.log("Upload attempted")
})
//Get file details
app.post('/files/ls',(req,res)=>{
console.log("Request attempted")
})
2019-05-19 12:21:40 +05:30
2019-05-21 10:38:54 +05:30
2019-05-19 18:48:50 +05:30
app.get( '/*', express.static( path.join(__dirname,'static') ) );
2019-05-19 12:21:40 +05:30
app.all('*',(req,res)=>{
res.status(404).json({'error':404});
})
app.listen(port,()=>{
2019-05-19 18:48:50 +05:30
console.log(`Listening : ${port}`)
2019-05-19 12:21:40 +05:30
})