Add routing basics

Add jquery
This commit is contained in:
2019-05-21 19:37:11 +05:30
parent 17f8fd3500
commit 4f01ee8cb8
7 changed files with 74 additions and 12 deletions

View File

@@ -23,26 +23,43 @@ app.get('/files',(req,res,next)=>{
next(err)
}
else{
res.json({"filename":`${DIR}`,"rootdir":processing.dirprocess(stream,settings)});
}
})
})
//Attempt to upload a file
//Attempt to upload a file - Placeholder
app.put('/files/upload',(req,res)=>{
console.log("Upload attempted")
})
//Get file details
app.post('/files/ls',(req,res)=>{
console.log("Request attempted")
res.json({'error':500})
})
app.get( '/*', express.static( path.join(__dirname,'static') ) );
//Get folder details
app.post('/files/ls',(req,res,next)=>{
const location = processing.mergedir(req.body.loc,settings)
fs.readdir(location,(err,files)=>{
if(err){
next(err)
}
else{
res.json({
"location": location ,
"contents":files
})
}
})
//next()
})
//console.log(path.join(__dirname ,'node_modules','jquery','dist'))
app.use('/jquery', express.static( path.join(__dirname ,'node_modules','jquery','dist') ) )
app.get( '/*', express.static( path.join(__dirname,'static') ) )
//All non-matched end up in this route
app.all('*',(req,res)=>{
res.status(404).json({'error':404});

5
package-lock.json generated
View File

@@ -192,6 +192,11 @@
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.0.tgz",
"integrity": "sha512-M4Sjn6N/+O6/IXSJseKqHoFc+5FdGJ22sXqnjTpdZweHK64MzEPAyQZyEU3R/KRv2GLoa7nNtg/C2Ev6m7z+eA=="
},
"jquery": {
"version": "3.4.1",
"resolved": "https://registry.npmjs.org/jquery/-/jquery-3.4.1.tgz",
"integrity": "sha512-36+AdBzCL+y6qjw5Tx7HgzeGCzC81MDDgaUP8ld2zhx58HdqXGoBd+tHdrBMiyjGQs0Hxs/MLZTu/eHNJJuWPw=="
},
"media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",

View File

@@ -22,6 +22,7 @@
"homepage": "https://github.com/chrisvrose/nodejs-fm#readme",
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.0"
"express": "^4.17.0",
"jquery": "^3.4.1"
}
}

View File

@@ -1,3 +1,8 @@
const paths = require('path')
module.exports.mergedir = (dirname,settings)=>{
return paths.join(settings.dirname,dirname);
}
module.exports.dirprocess = (dirstream,settings)=>{
if(!settings.showHidden){
let fdirstream = dirstream.filter((ele)=>{
@@ -5,6 +10,8 @@ module.exports.dirprocess = (dirstream,settings)=>{
})
return fdirstream
}
else return dirstream
else{
return dirstream
}
}

View File

@@ -83,6 +83,22 @@ body{
margin-top:0.5rem;
}
table#files-details{
width:100%;
}
table{
border-collapse: collapse;
}
table tr{
border-bottom: 1px #c5c0c0 solid;
}
table td{
padding:0.25em;
}
tbody tr:last-child{
border:0;
}
.box-shadow-1{
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);

8
static/base.js Normal file
View File

@@ -0,0 +1,8 @@
let currDir = '/';
//set table details
function setList(){
}

View File

@@ -4,6 +4,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>FM</title>
<link rel="stylesheet" href="base.css" />
<script src="jquery/jquery.min.js"></script>
<script src="base.js"></script>
</head>
<body>
<div class="navbar-container box-shadow-1">
@@ -15,14 +17,20 @@
<div class="container">
<div class="content box-shadow-1">
<table id="files-details">
<thead>
<tr>
<td>File Name</td>
<td>Actions</td>
</tr>
</thead>
<tbody>
<tr>
<td>TEST1</td>
<td>TEST2</td>
<td class="file-handlers">TEST2</td>
</tr>
<tr>
<td>TEST3</td>
<td>TEST4</td>
<td class="file-handlers">TEST4</td>
</tr>
</tbody>
</table>