Skip to content
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
5 changes: 3 additions & 2 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ if (!fs.existsSync(path)) {
const isFile = fs.lstatSync(path).isFile();
let fileName;
if (isFile) {
const directoryPath = path.substring(0, path.lastIndexOf('/') + 1);
fileName = path.substring(path.lastIndexOf('/') + 1, path.length);
const index = path.lastIndexOf('/');
const directoryPath = path.substring(0, index + 1);
fileName = path.substring(index, path.length);
path = directoryPath;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/middleware/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ const fileUpload = async (req, res, { path } = {}) => {
await new Promise((resolve, reject) => {
form.parse(req, (err, fields, files) => {
if (err) throw err;
const oldpath = files.filetoupload.filepath;
let newPath = appendSlash(path) + files.filetoupload.originalFilename;
const { filepath, originalFilename } = files.filetoupload;
let newPath = appendSlash(path) + originalFilename;
if (fs.existsSync(newPath)) {
newPath = `${appendSlash(path) + new Date().getTime()}_${files.filetoupload.originalFilename}`;
newPath = `${appendSlash(path) + new Date().getTime()}_${originalFilename}`;
}
try {
fs.moveSync(oldpath, newPath);
fs.moveSync(filepath, newPath);
} catch (error) {
reject(error);
}
Expand Down
Loading