-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
144 lines (124 loc) · 3.87 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const path = require("path");
const fs = require("fs");
const express = require("express");
const jetpack = require("fs-jetpack");
const yaml = require('js-yaml');
let port = 3000;
const app = express();
if(process.env.NODE_ENV === 'dev'){
const livereload = require("livereload");
const connectLivereload = require("connect-livereload");
const liveReloadServer = livereload.createServer();
liveReloadServer.watch(path.join(__dirname, "views"));
liveReloadServer.server.once("connection", () => {
setTimeout(() => {
pagetodebug = "/"+""
liveReloadServer.refresh(pagetodebug);
}, 50);
});
app.use(connectLivereload());
}
let foldersource, folderoutput
// app.use(cors())
app.use(express.json({ limit: '100mb' }));
app.use(express.urlencoded({ extended: true, limit: '100mb' }));
try{
var filename = path.join(__dirname, './settings.yml'),
contents = fs.readFileSync(filename, 'utf8'),
datayaml = yaml.load(contents);
port = datayaml.app.port
foldersource = datayaml.app.foldersource
folderoutput = datayaml.app.folderoutput
}catch(err){
console.log(err)
}
app.use('/assets', express.static('assets'))
app.set("view engine", "ejs");
app.get("/", (req, res) => {
res.render("index");
});
app.get("/file", (req, res) => {
res.render("file", { title: "file" });
});
app.get("/bt", (req, res) => {
res.render("bt", { title: "file" });
});
app.get('/static', async (req, res, next) => {
try {
let loc = req.query.loc
let type = req.query.type
loc = path.join(__dirname,foldersource, loc)
if(jetpack.exists(loc)){
res.sendFile(loc);
}else{
res.status(500).json({success:false})
}
} catch (err) { next(err)}
});
app.get("/allfiles", (req, res) => {
// let files = jetpack.find(foldersource, { matching:"/**/*.pdf" });
let files = jetpack.find(foldersource, { matching:"**/*.pdf" });
for (var i1 = files.length - 1; i1 >= 0; i1--) {
// let loc = files[i1]
let loc = files[i1].split("\\").splice(2,2).join("/")
let name = loc
// let arloc = loc.split("/")
// let name = arloc[arloc.length-1]
files[i1] = {loc:loc,name:name}
}
return res.status(200).json({success:true,rows:files})
});
app.get("/readyfiles", (req, res) => {
// let files = jetpack.find(foldersource, { matching:"/**/*.pdf" });
let files = jetpack.find(folderoutput, { matching:"**/*.pdf" });
for (var i1 = files.length - 1; i1 >= 0; i1--) {
loc = files[i1].split("\\").splice(2,2).join("/")
files[i1] = {loc:loc,name:loc}
}
return res.status(200).json({success:true,rows:files})
});
app.post("/rename", (req, res) => {
const data = req.body
// console.log(data)
source = path.join(foldersource, data.source)
dest = path.join(folderoutput, data.dest)
// console.log(source,dest)
if(jetpack.exists(source)){
jetpack.move(source, dest);
return res.status(200).json({success:true,rows:dest})
}else{
return res.status(500).json({success:false,message:"Not Exists"})
}
});
app.post('/rxw', async (req, res, next) => {
try {
let osnya = os.platform()
const obj = req.body.data
if(osnya=='win32'){
let strobj = JSON.stringify(obj)
strobj = JSON.stringify(strobj)
if(strobj.indexOf("^")>-1){
strobj = strobj.split("^").join("^^")
}
if(strobj.indexOf("&")>-1){
strobj = strobj.split("&").join("^&")
}
if(strobj.indexOf(">")>-1){
strobj = strobj.split(">").join("^>")
}
if(strobj.indexOf("<")>-1){
strobj = strobj.split("<").join("^<")
}
// jetpack.write( batloc, '"'+globalval.wrkrlocation+'" '+strobj+' \n exit')
// exec('start "" "'+batloc+'"')
exec(`start "" "node.exe wrkr ${strobj}`)
}
res.json({ "Success": true })
} catch (err) {
next(err)
}
});
//listen for requests
app.listen(port, () => {
console.log(`Server is listening at http://localhost:${port}`);
});