backup
This commit is contained in:
1 parent
c1346c312c
commit
44d0f561f6
6 files changed
+29
-15
No files matched your search
@@ -5,7 +5,6 @@ function hash(m, salt) {
|
|||||||
var result = "";
|
var result = "";
|
||||||
if (m.length != 24) throw "Invalid id";
|
if (m.length != 24) throw "Invalid id";
|
||||||
for (var i = 0; i < 12; i++) {
|
for (var i = 0; i < 12; i++) {
|
||||||
//console.log(x.charAt(i));
|
|
||||||
playground = 0;
|
playground = 0;
|
||||||
playground += salt.charCodeAt(i);
|
playground += salt.charCodeAt(i);
|
||||||
playground ^= m.charCodeAt(i);
|
playground ^= m.charCodeAt(i);
|
||||||
@@ -26,7 +25,7 @@ function getKeys(uid) {
|
|||||||
Admin: hash(uid, saltAdmin),
|
Admin: hash(uid, saltAdmin),
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
keys = { err: "Invalid id" };
|
keys = { err: error };
|
||||||
}
|
}
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
Binary file not shown.
@@ -2,9 +2,17 @@ const express = require("express");
|
|||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
|
const lastFilesDir = "./public/upload/converted/";
|
||||||
|
|
||||||
|
const renderPageName = "invoice_sign";
|
||||||
|
|
||||||
|
// load the page
|
||||||
router.get("/", function (req, res) {
|
router.get("/", function (req, res) {
|
||||||
let lastFiles = [];
|
let lastFiles = [];
|
||||||
const dir = fs.opendirSync("./uploads/converted/");
|
if (!fs.existsSync(lastFilesDir)) {
|
||||||
|
fs.mkdirSync(lastFilesDir);
|
||||||
|
}
|
||||||
|
const dir = fs.opendirSync(lastFilesDir);
|
||||||
let entity;
|
let entity;
|
||||||
while ((entity = dir.readSync()) !== null) {
|
while ((entity = dir.readSync()) !== null) {
|
||||||
if (entity.isFile()) {
|
if (entity.isFile()) {
|
||||||
@@ -13,8 +21,7 @@ router.get("/", function (req, res) {
|
|||||||
lastFiles.push({ type: "d", name: entity.name });
|
lastFiles.push({ type: "d", name: entity.name });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(lastFiles);
|
res.render(renderPageName, { lastFiles });
|
||||||
res.render("invoice_sign", { lastFiles });
|
|
||||||
});
|
});
|
||||||
//Post the upload file
|
//Post the upload file
|
||||||
// For handling the upload request
|
// For handling the upload request
|
||||||
@@ -28,10 +35,12 @@ router.post("/", function (req, res) {
|
|||||||
console.log(uploadedFile);
|
console.log(uploadedFile);
|
||||||
|
|
||||||
// Upload path
|
// 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
|
// To save the file using mv() function
|
||||||
uploadedFile.mv(uploadPath, function (err) {
|
uploadedFile.mv(uploadPath + uploadedFile.name, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
res.send("Failed !!");
|
res.send("Failed !!");
|
||||||
@@ -43,10 +52,14 @@ router.post("/", function (req, res) {
|
|||||||
// To handle the download file request
|
// To handle the download file request
|
||||||
router.get("/download", function (req, res) {
|
router.get("/download", function (req, res) {
|
||||||
// The res.download() talking file path to be downloaded
|
// The res.download() talking file path to be downloaded
|
||||||
res.download(__dirname + "/uploads/fax.odg", function (err) {
|
// console.log(req);
|
||||||
if (err) {
|
// res.download(__dirname + "/uploads/fax.odg", function (err) {
|
||||||
console.log(err);
|
// if (err) {
|
||||||
}
|
// console.log(err);
|
||||||
});
|
// }
|
||||||
|
// });
|
||||||
|
const downloadFile = lastFilesDir + req.query.downloadFile;
|
||||||
|
console.log(downloadFile);
|
||||||
|
res.download(downloadFile, function (err) {});
|
||||||
});
|
});
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
Binary file not shown.
@@ -11,4 +11,6 @@ block content
|
|||||||
button(type='submit') Download
|
button(type='submit') Download
|
||||||
ul
|
ul
|
||||||
each file in lastFiles
|
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>";
|
HTML += "</tr></table>";
|
||||||
resp.innerHTML = HTML;
|
resp.innerHTML = HTML;
|
||||||
}else{
|
}else{
|
||||||
resp.innerHTML = "invalid input"
|
resp.innerHTML = keys.err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user