-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
73 lines (71 loc) · 2.07 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const express = require("express");
const fs = require("fs");
const fileUpload = require("express-fileupload");
const index = require("./index");
//const script = require("./script");
const app = express();
const PORT = 5000 || process.env.PORT;
app.use(fileUpload());
app.use(express.static("public"));
app.get("/", (req, res) => {
res.sendFile(`${__dirname}/public/index.html`);
});
app.post("/uploadFile", (req, res) => {
if (req.files && Object.keys(req.files).length !== 0) {
const uploadedFile = req.files.uploadFile;
const uploadPath = __dirname + "/upload/" + uploadedFile.name;
uploadedFile.mv(uploadPath, function (err) {
if (err) {
console.log(err);
res.send(err);
} else {
//script.showModal();
res.redirect("/#uploadfile");
}
});
} else res.send("No file uploaded !!");
});
app.get("/convertFilestoVideo", async (req, res) => {
await index.convertFileToVideo();
res.redirect("/#tovideo");
});
app.get("/downloadVideo", async (req, res) => {
res.download(`${__dirname}/video/outputVideo.mp4`, function (err) {
if (err) {
console.log(err);
}
fs.unlinkSync(`${__dirname}/video/outputVideo.mp4`);
});
});
app.post("/uploadVideo", (req, res) => {
if (req.files && Object.keys(req.files).length !== 0) {
const uploadedFile = req.files.uploadFile;
const uploadPath = __dirname + "/uploadedVideo/outputVideo.mp4";
uploadedFile.mv(uploadPath, function (err) {
if (err) {
console.log(err);
res.send(err);
} else {
res.redirect("/#uploadVideoid");
}
});
} else res.send("No file uploaded !!");
});
app.get("/convertVideoToFrames", async (req, res) => {
await index.convertVideoToFile();
res.redirect("/#downloadFileId");
});
app.get("/downloadFile", (req, res) => {
res.download(`${__dirname}/output/output.zip`, function (err) {
if (err) {
console.log(err);
}
fs.unlinkSync(`${__dirname}/output/output.zip`);
});
});
app.listen(PORT, (err) => {
if (err) {
console.log(err);
}
console.log("Port started on " + PORT);
});