Skip to content

Commit

Permalink
File Folder Remoev Functionality issue cube-root#14
Browse files Browse the repository at this point in the history
  • Loading branch information
tornikeshavishvili committed Nov 5, 2022
1 parent cc02cc2 commit cea3ef2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/middleware/directory.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions lib/middleware/file-remove.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

const fs = require('fs-extra');

const fileRemove = async (req, res, { path } = {}) => {

await new Promise((resolve, reject) => {

fs.remove(path, err => {
if(err) {
reject(err);
}else{
resolve();
}

});

});
return res.redirect('/');
};

module.exports = {
fileRemove,
};
8 changes: 8 additions & 0 deletions lib/middleware/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
const querystring = require('node:querystring');
const { directory } = require('./directory');
const { fileUpload } = require('./file-upload');
const { fileRemove } = require('./file-remove');
const { authMiddleware } = require('./auth');

const handler = (req, res, { path, uploadFile = true } = {}) => {

if(req.query.delete && req.query.delete.toLowerCase() === 'true'){
return fileRemove(req, res, {
path: path.replace(/[/]$/, '') + '/' + req.path.replace(/^[/]/, '')
});
}

if (req.method === 'POST' && uploadFile) {
const query = querystring.decode(req.url, null, null);
if (query && !query.path) {
Expand Down

0 comments on commit cea3ef2

Please sign in to comment.