You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
const express = require("express");
|
|
const router = express.Router();
|
|
const fs = require("fs");
|
|
|
|
router.get("/", function (req, res) {
|
|
let lastFiles = [];
|
|
const dir = fs.opendirSync("./uploads/converted/");
|
|
let entity;
|
|
while ((entity = dir.readSync()) !== null) {
|
|
if (entity.isFile()) {
|
|
lastFiles.push({ type: "f", name: entity.name });
|
|
} else if (entity.isDirectory()) {
|
|
lastFiles.push({ type: "d", name: entity.name });
|
|
}
|
|
}
|
|
console.log(lastFiles);
|
|
res.render("invoice_sign", { lastFiles });
|
|
});
|
|
//Post the upload file
|
|
// For handling the upload request
|
|
router.post("/", function (req, res) {
|
|
// When a file has been uploaded
|
|
if (req.files && Object.keys(req.files).length !== 0) {
|
|
// Uploaded path
|
|
const uploadedFile = req.files.uploadFile;
|
|
|
|
// Logging uploading file
|
|
console.log(uploadedFile);
|
|
|
|
// Upload path
|
|
const uploadPath = __dirname + "/../uploads/" + uploadedFile.name;
|
|
|
|
// To save the file using mv() function
|
|
uploadedFile.mv(uploadPath, function (err) {
|
|
if (err) {
|
|
console.log(err);
|
|
res.send("Failed !!");
|
|
} else res.send("Successfully Uploaded !!");
|
|
});
|
|
} else res.send("No file uploaded !!");
|
|
});
|
|
|
|
// 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);
|
|
}
|
|
});
|
|
});
|
|
module.exports = router;
|