diff --git a/Rev1/node/public/js/pGenerator.js b/Rev1/node/public/js/pGenerator.js index d63d66b..8a89b1d 100644 --- a/Rev1/node/public/js/pGenerator.js +++ b/Rev1/node/public/js/pGenerator.js @@ -5,7 +5,6 @@ function hash(m, salt) { var result = ""; if (m.length != 24) throw "Invalid id"; for (var i = 0; i < 12; i++) { - //console.log(x.charAt(i)); playground = 0; playground += salt.charCodeAt(i); playground ^= m.charCodeAt(i); @@ -26,7 +25,7 @@ function getKeys(uid) { Admin: hash(uid, saltAdmin), }; } catch (error) { - keys = { err: "Invalid id" }; + keys = { err: error }; } return keys; } diff --git a/Rev1/node/public/upload/converted/2141915A-PI Hong Kong.pdf b/Rev1/node/public/upload/converted/2141915A-PI Hong Kong.pdf new file mode 100644 index 0000000..339debd Binary files /dev/null and b/Rev1/node/public/upload/converted/2141915A-PI Hong Kong.pdf differ diff --git a/Rev1/node/routes/invoice_sign.js b/Rev1/node/routes/invoice_sign.js index fab79aa..29aa057 100644 --- a/Rev1/node/routes/invoice_sign.js +++ b/Rev1/node/routes/invoice_sign.js @@ -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; diff --git a/Rev1/node/uploads/2141915A-PI Hong Kong.pdf b/Rev1/node/uploads/2141915A-PI Hong Kong.pdf new file mode 100644 index 0000000..339debd Binary files /dev/null and b/Rev1/node/uploads/2141915A-PI Hong Kong.pdf differ diff --git a/Rev1/node/views/invoice_sign.pug b/Rev1/node/views/invoice_sign.pug index 76419a1..d9aac0f 100644 --- a/Rev1/node/views/invoice_sign.pug +++ b/Rev1/node/views/invoice_sign.pug @@ -11,4 +11,6 @@ block content button(type='submit') Download ul each file in lastFiles - li= file.name \ No newline at end of file + //- li= file.name + form(method='get',action='/invoice_sign/download') + input(type='submit', name='downloadFile', value=file.name) \ No newline at end of file diff --git a/Rev1/node/views/p_generator.pug b/Rev1/node/views/p_generator.pug index 3cce6cd..04d2b15 100644 --- a/Rev1/node/views/p_generator.pug +++ b/Rev1/node/views/p_generator.pug @@ -24,7 +24,7 @@ block content HTML += ""; resp.innerHTML = HTML; }else{ - resp.innerHTML = "invalid input" + resp.innerHTML = keys.err }