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.
84 lines
2.3 KiB
JavaScript
84 lines
2.3 KiB
JavaScript
const express = require("express");
|
|
const path = require("path");
|
|
const routes = require("./views/routes");
|
|
const fileUpload = require("express-fileupload");
|
|
const fs = require("fs");
|
|
|
|
const port = 3000;
|
|
|
|
// Init App
|
|
const app = express();
|
|
app.use(fileUpload());
|
|
app.set("view engine", "pug");
|
|
// Static Files
|
|
app.use(express.static("public"));
|
|
app.use("/css", express.static(__dirname + "public/css "));
|
|
app.use("/js", express.static(__dirname + "public/js "));
|
|
app.use("/img", express.static(__dirname + "public/img "));
|
|
|
|
app.get("/", function (req, res) {
|
|
res.render("index", routes);
|
|
});
|
|
app.get("/flasher", function (req, res) {
|
|
res.render("flasher", routes);
|
|
});
|
|
app.get("/p_generator", function (req, res) {
|
|
res.render("p_generator", routes);
|
|
});
|
|
app.get("/pcb_panel_bom", function (req, res) {
|
|
res.render("pcb_panel_bom", routes);
|
|
});
|
|
app.get("/invoice_sign", 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", { routes, lastFiles });
|
|
});
|
|
|
|
//Post the upload file
|
|
// For handling the upload request
|
|
app.post("/invoice_sign", 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
|
|
app.get("/invoice_sign/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);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Start Server
|
|
app.listen(port, function () {
|
|
console.log(`Server started on port ${port}...`);
|
|
});
|