Skip to content

I have addressed All Issues #14 and #15 #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion lib/helper/html.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const fs = require('fs');
console.log(__dirname);
const createHtmlResponse = (body) => (
'<!DOCTYPE html>\n'
+ '<html lang="en">\n'
+ '<head>\n'
+ '<script src="https://cdn.tailwindcss.com"></script>'
// + '<script src="https://cdn.tailwindcss.com"></script>'
+ '<script>'
+ fs.readFileSync(__dirname + '/tailwind.js', 'utf8')
+ '</script>'
+ `<script type="text/javascript">

function beforeFileUpload(evnt){
var files = document.getElementsByName('filetoupload')[0].files;
if(!(files && files.length > 0 && files[0])){
Expand All @@ -15,6 +21,38 @@ const createHtmlResponse = (body) => (
}, 3500)
}
}

function nameClick(evnt, sender){

if(event.currentTarget !== evnt.target ){
evnt.preventDefault();
}

if(evnt.target.tagName.toLowerCase() !== 'button') { return false; }

var spn = sender.querySelector('span');
var inp = sender.querySelector('input');

if(inp.style.display !== 'block'){
spn.style.display = 'none';
inp.style.display = 'block';
inp.focus();
}else{
spn.style.display = 'block';
inp.style.display = 'none';
}

}

function renameInput(evnt, sender){
// console.log(evnt.key.toLowerCase() )
if(evnt.key.toLowerCase() === 'enter'){
let newHref = sender.parentNode.getAttribute("href").split('rename')[0]+'rename='+sender.value;
sender.parentNode.setAttribute("href", newHref)
sender.parentNode.click();
}
}

</script>`
+ '<meta charset="utf-8">\n'
+ '<meta name="viewport" content="width=device-width, initial-scale=1.0">'
Expand Down
63 changes: 63 additions & 0 deletions lib/helper/tailwind.js

Large diffs are not rendered by default.

58 changes: 51 additions & 7 deletions lib/middleware/directory.js

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

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

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

const fileRename = async (req, res, { currentPath, newPath } = {}) => {

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

fs.rename(currentPath, newPath, (err) => {
if(err) {
reject(err);
}else{
resolve();
}
});

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

module.exports = {
fileRename,
};
19 changes: 16 additions & 3 deletions lib/middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@ const querystring = require('node:querystring');
const { directory } = require('./directory');
const { fileUpload } = require('./file-upload');
const { fileRemove } = require('./file-remove');
const { fileRename } = require('./file-rename');
const { authMiddleware } = require('./auth');

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

if(req.query.rename){
let currentPath = path.replace(/[/]$/, '') + '/' + req.path.replace(/^[/]/, '');
let newPath = currentPath.split('/');
newPath.pop()
newPath.push(req.query.rename);
newPath = newPath.join('/')
return fileRename(req, res, {
currentPath: decodeURI(currentPath),
newPath: decodeURI(newPath)
});
}

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

Expand All @@ -18,8 +31,8 @@ const handler = (req, res, { path, uploadFile = true } = {}) => {
return res.status(500).send('Invalid path');
}
return fileUpload(req, res, {
path: query.path,
originalPath: path,
path: decodeURI(query.path),
originalPath: decodeURI(path),
uploadFile,
});
}
Expand Down