File Downloading

This commit is contained in:
2019-05-24 14:41:30 +05:30
parent 464c6c1c3f
commit a87092d3e8
5 changed files with 52 additions and 17 deletions

View File

@@ -46,5 +46,6 @@ Responses (Only for directory traversals):
## Credit ## Credit
- Samuel Thornton: [Material Design Box Shadows]("https://codepen.io/sdthornton/pen/wBZdXq") - Samuel Thornton: [Material Design Box Shadows]("https://codepen.io/sdthornton/pen/wBZdXq")
- Chris Pratt: [File Download via Ajax]('https://codepen.io/chrisdpratt/pen/RKxJNo')
- StackOverflow: Troubleshooting errors - StackOverflow: Troubleshooting errors
- Google: All knowing - Google: All knowing

View File

@@ -22,6 +22,7 @@ let inDir = (dircheck,dirmain) => !path.relative(path.normalize(dircheck), dirma
//Get folder details //Get folder details
app.post('/files/cat',(req,res,next)=>{ app.post('/files/cat',(req,res,next)=>{
console.log(req.body)
const location = processing.mergedir(req.body.loc,settings) const location = processing.mergedir(req.body.loc,settings)
//const nloc = path.normalize(req.body.loc); //const nloc = path.normalize(req.body.loc);
const nloc = path.normalize(path.relative(settings.dirname,location)) const nloc = path.normalize(path.relative(settings.dirname,location))
@@ -67,6 +68,8 @@ app.put('/files/upload',(req,res)=>{
console.log("Upload attempted") console.log("Upload attempted")
res.json({'error':500}) res.json({'error':500})
}) })
// Use font-awesome
app.use('/fa',express.static(path.join(__dirname,'node_modules','@fortawesome','fontawesome-free')))
// Use jquery // Use jquery
app.use('/jquery', express.static( path.join(__dirname ,'node_modules','jquery','dist') ) ) app.use('/jquery', express.static( path.join(__dirname ,'node_modules','jquery','dist') ) )
@@ -86,6 +89,7 @@ app.listen(port,()=>{
}) })
app.use((err,req,res,next)=>{ app.use((err,req,res,next)=>{
console.log(err)
res.status(500).json({error:`Internal error.Try again.`}) res.status(500).json({error:`Internal error.Try again.`})
}) })

View File

@@ -65,9 +65,9 @@ body{
background-color:aliceblue; background-color:aliceblue;
z-index:2; z-index:2;
padding:0.5rem; padding:0.5rem;
height: 1.5rem; height: 2rem;
width:100%; width:100%;
font-size:1.5em;
} }
.nav-bottom-button-container{ .nav-bottom-button-container{
width:100%; width:100%;
@@ -94,6 +94,14 @@ body{
margin-top:0.5rem; margin-top:0.5rem;
} }
.icon-tabs{
float:right;
padding-right:1em;
}
.icon-tabs .file-download-button,.icon-tabs .file-rename-button{
margin-left:0.5em;
}
table#files-details{ table#files-details{
width:100%; width:100%;
} }

View File

@@ -1,15 +1,16 @@
let currDir = {'loc':'','contents':null}; let currDir = {'loc':'','contents':null}
let currSel = {'loc':'','path':''} let currSel = {'loc':null,'name':null}
function doUpdate(ele,isDir=false){ function doUpdate(ele,isDir=false){
//console.log(ele.attr('data-choice')); //console.log(ele.attr('data-choice'));
if(ele.hasClass('file-isDir')){ if(ele.hasClass('file-isDir')){
currDir.loc = ele.attr('data-choice'); currDir.loc = ele.attr('data-choice')
populateContents(); populateContents();
} }
if(!isDir){ if(!isDir){
$('.nav-bottom-text').html(ele.html()) currSel.loc = ele.attr('data-choice')
$('.nav-bottom-text').html(currSel.name = ele.html())
} }
//$() //$()
@@ -57,5 +58,21 @@ function populateContents(){
$(document).ready(()=>{ $(document).ready(()=>{
populateContents(); populateContents();
//updateContents(); $('.file-download-button').click(()=>{
console.log(currSel)
$.ajax('/files/cat',{
method:'post',
data:currSel,
xhrFields: {
responseType: 'blob'
},
success:(msg)=>{
//console.log(msg)
$('.file-download-button').after(`<a id="down-temp" href="${window.URL.createObjectURL(msg)}" download="${currSel.name}"></a>`)
document.getElementById('down-temp').click()
$('#down-temp').remove();
},
error: err=>console.log(err)
})
})
}) })

View File

@@ -5,13 +5,14 @@
<title>FM</title> <title>FM</title>
<link rel="stylesheet" href="base.css" /> <link rel="stylesheet" href="base.css" />
<script src="jquery/jquery.min.js"></script> <script src="jquery/jquery.min.js"></script>
<script src="fa/js/all.js"></script>
<script src="base.js"></script> <script src="base.js"></script>
</head> </head>
<body> <body>
<div id="cover" class="hidden"></div> <div id="cover" class="hidden"></div>
<div class="navbar-container box-shadow-1"> <div class="navbar-container box-shadow-1">
<div class="navbar"> <div class="navbar">
<div class="navbar-text">Location: /<span id="files-location"></span></div> <div class="navbar-text">Location: <span id="files-location"></span></div>
</div> </div>
</div> </div>
@@ -25,14 +26,7 @@
</tr> </tr>
</thead> </thead>
<tbody id="files-table"> <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>-->
</tbody> </tbody>
</table> </table>
</div> </div>
@@ -44,7 +38,18 @@
<button class="nav-bottom-button box-shadow-3 box-shadow-3-active">+</button> <button class="nav-bottom-button box-shadow-3 box-shadow-3-active">+</button>
</div> </div>
<div class="nav-bottom box-shadow-3"> <div class="nav-bottom box-shadow-3">
<span class="nav-bottom-text">Select file</span> <span class="nav-bottom-text">
Select file
</span>
<span class="icon-tabs">
<span class="file-download-button" alt="Download">
<span class="fas fa-file-download"></span>
</span>
<span class="file-rename-button" alt="Rename">
<span class="fas fa-file-export"></span>
</span>
</span>
</div> </div>
</div> </div>
</body> </body>