-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
140 lines (123 loc) · 4.11 KB
/
app.js
File metadata and controls
140 lines (123 loc) · 4.11 KB
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
let compression = require('compression');
const express = require('express'),
path = require('path'),
fs = require('fs'),
app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(compression());
app.use(express.static(path.join(__dirname, 'public')));
app.get("/", (req, res) => {
res.render(`pages/homepage`);
});
app.get("/cheats", (req, res) => {
let id = req.query.id;
fs.readdir('./views/pages/cheats/', (err, count) => {
if(id != "") {
if(isNaN(id) == false) {
if(id < count.length) {
let game_info = JSON.parse(fs.readFileSync(`./views/pages/cheats/${id}/info.json`));
let data = JSON.parse(fs.readFileSync(`./views/pages/cheats/${id}/codes.json`));
let total_count = 0;
for(i in data) {
if(data[i].display == true) {
total_count += 1;
}
}
let showcode = null;
if("showcode" in req.query) {
let data_showcode = req.query.showcode;
if(data_showcode != "") {
if(!isNaN(data_showcode)) {
try {
if(data[data_showcode].display == true) {
showcode = data_showcode;
}
} catch {
showcode = null;
}
}
}
}
if("search" in req.query) {
let search = req.query.search;
if(search != "") {
let newData = [];
found = 0;
for(i in data) {
if(data[i].title.toLowerCase().includes(search.toLowerCase())) {
if(data[i].display == true) {
newData.push(data[i]);
found += 1;
}
}
}
return res.render(`pages/cheatcodes`, {data: newData, game_info: game_info, total_count: total_count, search: search,found: found, showcode: showcode});
}
}
return res.render(`pages/cheatcodes`, {data: data, game_info: game_info, total_count: total_count, search: null,found: null, showcode: showcode});
}
}
}
let data = [];
for(f in count) {
let json_data = JSON.parse(fs.readFileSync(`./views/pages/cheats/${f}/info.json`));
data.push(json_data);
}
res.render('pages/cheats', {data});
});
});
app.get("/api", (req, res) => {
res.render("pages/api")
});
app.get(["/api/list", "/api/game", "/api/games"], (req, res) => {
fs.readdir('./views/pages/cheats/', (err, count) => {
let data = [];
for(f in count) {
let json_data = JSON.parse(fs.readFileSync(`./views/pages/cheats/${f}/info.json`));
data.push({
"id": json_data['id'],
"name": json_data['name']
});
}
res.json(data);
});
});
app.get("/api/info", (req, res) => {
let id = req.query.id;
fs.readdir('./views/pages/cheats/', (err, count) => {
if(isNaN(id) == false && id != "") {
if(id < count.length) {
return res.json(JSON.parse(fs.readFileSync(`./views/pages/cheats/${id}/info.json`)));
}
}
res.json({"Status": "Error", "info": "Please check that you have entered a valid identifier!"});
});
});
app.get(["/api/cheat", "/api/cheats"], (req, res) => {
let id = req.query.id;
fs.readdir('./views/pages/cheats/', (err, count) => {
if(isNaN(id) == false && id != "") {
if(id < count.length) {
return res.json(JSON.parse(fs.readFileSync(`./views/pages/cheats/${id}/codes.json`)));
}
}
res.json({"Status": "Error", "info": "Please check that you have entered a valid identifier!"});
});
});
app.get(["/api/cheatinfo", "/api/cheatsinfo"], (req, res) => {
let gid = req.query.gid;
let cid = req.query.cid;
if(gid == "" || isNaN(gid)) {return res.json({"Status": "Error", "info": "Please check that you have entered a valid GID (Game ID!"});}
if(cid == "" || isNaN(cid)) {return res.json({"Status": "Error", "info": "Please check that you have entered a valid CID (Cheat ID)!"});}
fs.readdir('./views/pages/cheats', (err, count) => {
if(gid < count.length) {
json = JSON.parse(fs.readFileSync(`./views/pages/cheats/${gid}/codes.json`));
if(!json[cid]) {return res.json({"Status": "Error", "info": "Unknown cheat code"});}
return res.json(json[cid]);
} else {return res.json({"Status": "Error", "info": "Unknown games"});}
});
});
app.listen(process.env.PORT || 3000, () => {
console.log(`Server is running...`);
});