-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
189 lines (164 loc) · 5.08 KB
/
server.js
File metadata and controls
189 lines (164 loc) · 5.08 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
const express = require('express');
const request = require('request');
const cheerio = require('cheerio');
const cors = require('cors');
const mv = express();
const port = 5000;
mv.use(cors());
mv.use(express.json());
/*const MANGA_TYPE_1 = [
"ONE PUNCH MAN",
"TOKYO GHOUL",
"ONE PIECE",
"JUJUTSU KAISEN",
"BORUTO",
"DR. STONE",
]; */
//
// Fetch A Manga with All The Chapters' Name & Link
//
mv.get('/manga/:source/:manga/:link', (req, res) => {
console.log(`hello from the other side -> ${new Date()} `);
const { link, source } = req.params;
const newLink = link.replace(/,/g, '/');
let resData = {
title: '',
chapters: []
};
fetch(newLink)
.then((response) => {
console.log('body', response.body);
console.log('headers', response.headers);
console.log('status', response.status);
console.log('statusText', response.statusText);
return response.text();
})
.then((html) => {
const $ = cheerio.load(html);
if (source === 'idkmanga') {
resData.title = $('.entry-title').text();
$('#Chapters_List')
.children('ul')
.children('li')
.children('ul')
.children('li')
.each((i, chapter) => {
const arr = $(chapter).children('a').text().split(' ');
const data = {
chapterName: $(chapter).children('a').text(),
chapterLink: $(chapter).children('a').attr('href'),
chapterId: arr.includes('Chapter')
? arr[arr.indexOf('Chapter') + 1]
: arr.includes('Redraw')
? arr[arr.indexOf('Redraw') + 1]
: arr.includes('Number')
? arr[arr.indexOf('Number') + 1]
: arr[arr.indexOf('CHAPTER') + 1]
};
resData.chapters.push(data);
});
}
res.status(200).json(resData);
})
.catch((error) => {
console.log('error', error);
res.status(200).json({ wasif: 'putki' });
});
// request(newLink, (err, response, html) => {
// console.log("error", err);
// console.log("response", response.statusCode);
// console.log("newLink", newLink);
// if (!err && response.statusCode === 200) {
// console.log("yayy no error");
// const $ = cheerio.load(html);
// // ................................... idkmanga archi .......................................//
// if (source === "idkmanga") {
// // Title
// resData.title = $(".entry-title").text();
// // Chapters
// $("#Chapters_List")
// .children("ul")
// .children("li")
// .children("ul")
// .children("li")
// .each((i, chapter) => {
// const arr = $(chapter).children("a").text().split(" ");
// const data = {
// chapterName: $(chapter).children("a").text(),
// chapterLink: $(chapter).children("a").attr("href"),
// chapterId: arr.includes("Chapter")
// ? arr[arr.indexOf("Chapter") + 1]
// : arr.includes("Redraw")
// ? arr[arr.indexOf("Redraw") + 1]
// : arr.includes("Number")
// ? arr[arr.indexOf("Number") + 1]
// : arr[arr.indexOf("CHAPTER") + 1],
// };
// resData.chapters.push(data);
// });
// }
// res.status(200).json(resData);
// //
// } else {
// res.status(response.statusCode).send(err);
// }
// });
});
//
// Fetch An Individual Chpater
//
//const CHAPTER_TYPE_1 = ["ONE PUNCH MAN", "BORUTO", "JUJUTSU KAISEN"];
mv.get('/chapter/:source/:manga/:link', (req, res) => {
const { manga, link, source } = req.params;
const chapterLink = link.replace(/,/g, '/');
let resData = {
title: '',
images: []
};
request(chapterLink, (err, response, html) => {
if (!err && response.statusCode == 200) {
const $ = cheerio.load(html);
// ................................... idkmanga archi .......................................//
if (source === 'idkmanga') {
// Title
resData.title = $('.entry-title').text();
// Images
if (manga === 'One-Punch-Man' || manga === 'Boruto' || manga === 'Jujutsu-Kaisen') {
$('.entry-content')
.children('p')
.each((i, image) => {
if ($(image).children('img').attr('src') !== undefined) {
//
if ($(image).children('noscript').text() !== '') {
const url = $(image).children('noscript').text().split('"')[1];
resData.images.push(url);
} else {
const url = $(image).children('img').attr('src');
resData.images.push(url);
}
}
});
} else if (manga === 'One-Piece' || manga === 'Dr.-Stone' || manga === 'Tokyo-Ghoul') {
$('.lazy').each((i, image) => {
const url = $(image).attr('src');
resData.images.push(url);
});
}
}
// ....................................... mangabat archi .....................................//
else if (source === 'mangabat') {
//Title
resData.title = $('.panel-chapter-info-top').children('h1').text();
}
res.status(200).json(resData);
} else {
res.status(404).send(err);
}
});
});
//
//
//
mv.listen(process.env.PORT || port, () => {
console.log(`MV is listening at http://localhost:${port}`);
});