This repository has been archived by the owner on Oct 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
131 lines (107 loc) · 3.07 KB
/
index.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
const express = require('express');
const api = require("./api");
const app = express();
const port = 8080;
app.set("views", "./static/");
app.use(express.static("./public/"))
app.engine('html', require('ejs').renderFile);
app.get("/search/", (req, res) => {
const name = req.query.q;
api.search(name).then((response) => {
res.send(response);
});
});
app.get("/chapters/:id/", async (req, res) => {
const id = req.params.id;
var return_data = {
"id_serie": undefined,
"url_name": undefined,
"name": undefined,
"chapters": []
};
for (let i = 1; ; i ) {
var result = await api.getChapters(id, i);
// checa se as infos ja foram adicionadas para evitar ficar reescrevendo os valores.
if (!return_data.name) {
return_data.id_serie = result.id_serie;
return_data.url_name = result.url_name;
return_data.name = result.name;
}
if (result.chapters.length > 0) {
return_data.chapters = return_data.chapters.concat(result.chapters);
continue;
}
break;
}
res.send(return_data);
});
app.get("/chapters/:id/:page/", async (req, res) => {
const id = req.params.id;
const page = req.params.page;
var return_data = {
"id_serie": undefined,
"url_name": undefined,
"name": undefined,
"chapters": []
};
var result = await api.getChapters(id, page);
return_data.chapters = result.chapters;
// checa se as infos já foram adicionadas para evitar ficar reescrevendo os valores.
if (!return_data.name) {
return_data.id_serie = result.id_serie;
return_data.url_name = result.url_name;
return_data.name = result.name;
}
res.send(return_data);
});
app.get("/pages/:id", (req, res) => {
const id = req.params.id;
api.getPages(id).then((pages) => {
res.send(pages);
});
});
app.get("/genres/", (_req, res) => {
api.getGenres().then((response) => {
res.send(response);
});
});
app.get("/recents", (req, res) => {
res.redirect("/recents/1");
});
app.get("/recents/:page", (req, res) => {
const page = req.params.page;
api.getRecents(page).then((response) => {
res.send(response);
});
});
app.get("/popular/", async (_req, res) => {
res.redirect("/popular/1");
});
app.get("/popular/:page", (req, res) => {
const page = req.params.page;
api.getPopular(page).then((response) => {
res.send(response);
});
});
app.get("/top/:page", (req, res) => {
const page = req.params.page;
api.getTop(page).then((response) => {
res.send(response);
});
});
app.get("/top/", async (_req, res) => {
res.redirect("/top/1");
});
app.get("/manga/:id", async(req, res) => {
const id = req.params.id;
api.getMangaById(id).then((response) => {
res.send(response);
});
});
app.get('*', (req, res) => {
res.header("401");
res.render("html/401.html");
});
app.listen(port, () => {
console.log(`Running at http://localhost:${port}/`);
});