master
Selcuk Sari 4 years ago
parent c1346c312c
commit 44d0f561f6

@ -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;
}

@ -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;

@ -11,4 +11,6 @@ block content
button(type='submit') Download
ul
each file in lastFiles
li= file.name
//- li= file.name
form(method='get',action='/invoice_sign/download')
input(type='submit', name='downloadFile', value=file.name)

@ -24,7 +24,7 @@ block content
HTML += "</tr></table>";
resp.innerHTML = HTML;
}else{
resp.innerHTML = "invalid input"
resp.innerHTML = keys.err
}

Loading…
Cancel
Save