backup
This commit is contained in:
1 parent
c1346c312c
commit
44d0f561f6
6 files changed
+29
-15
No files matched your search
@@ -2,9 +2,17 @@ const express = require("express");
|
||||
const router = express.Router();
|
||||
const fs = require("fs");
|
||||
|
||||
const lastFilesDir = "./public/upload/converted/";
|
||||
|
||||
const renderPageName = "invoice_sign";
|
||||
|
||||
// load the page
|
||||
router.get("/", function (req, res) {
|
||||
let lastFiles = [];
|
||||
const dir = fs.opendirSync("./uploads/converted/");
|
||||
if (!fs.existsSync(lastFilesDir)) {
|
||||
fs.mkdirSync(lastFilesDir);
|
||||
}
|
||||
const dir = fs.opendirSync(lastFilesDir);
|
||||
let entity;
|
||||
while ((entity = dir.readSync()) !== null) {
|
||||
if (entity.isFile()) {
|
||||
@@ -13,8 +21,7 @@ router.get("/", function (req, res) {
|
||||
lastFiles.push({ type: "d", name: entity.name });
|
||||
}
|
||||
}
|
||||
console.log(lastFiles);
|
||||
res.render("invoice_sign", { lastFiles });
|
||||
res.render(renderPageName, { lastFiles });
|
||||
});
|
||||
//Post the upload file
|
||||
// For handling the upload request
|
||||
@@ -28,10 +35,12 @@ router.post("/", function (req, res) {
|
||||
console.log(uploadedFile);
|
||||
|
||||
// Upload path
|
||||
const uploadPath = __dirname + "/../uploads/" + uploadedFile.name;
|
||||
|
||||
const uploadPath = lastFilesDir;
|
||||
if (!fs.existsSync(uploadPath)) {
|
||||
fs.mkdirSync(uploadPath);
|
||||
}
|
||||
// To save the file using mv() function
|
||||
uploadedFile.mv(uploadPath, function (err) {
|
||||
uploadedFile.mv(uploadPath + uploadedFile.name, function (err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
res.send("Failed !!");
|
||||
@@ -43,10 +52,14 @@ router.post("/", function (req, res) {
|
||||
// To handle the download file request
|
||||
router.get("/download", function (req, res) {
|
||||
// The res.download() talking file path to be downloaded
|
||||
res.download(__dirname + "/uploads/fax.odg", function (err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
// console.log(req);
|
||||
// res.download(__dirname + "/uploads/fax.odg", function (err) {
|
||||
// if (err) {
|
||||
// console.log(err);
|
||||
// }
|
||||
// });
|
||||
const downloadFile = lastFilesDir + req.query.downloadFile;
|
||||
console.log(downloadFile);
|
||||
res.download(downloadFile, function (err) {});
|
||||
});
|
||||
module.exports = router;
|
||||
Reference in new issue
Block a user