This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kaguya-reader.mjs
87 lines (58 loc) · 1.5 KB
/
kaguya-reader.mjs
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
import fetch from "node-fetch";
/*
/media/manga/<slug>/chapters/<folder>/<group_id>/<filename>
*/
let data = getInfo();
export function getPage(folder, group_id, filename) {
return new Promise((resolve, reject) => {
try {
fetch(
"https://guya.moe/media/manga/Kaguya-Wants-To-Be-Confessed-To/chapters/" +
folder + "/" +
group_id + "/" +
filename
).then(
response => response.buffer()
).then(buffer =>
resolve(buffer.toString("base64"))
);
} catch (err) {
reject(err);
}
});
// To display image, do <img src="data:image/png;base64,<%=image%>"/>
}
// info = { chapter information }; Look at lines 25 - 67 in kaguya-data-3-11-21.json for example.
export async function getChapter(chapterInfo) {
const id = Object.keys(chapterInfo.groups)[0];
const images = [];
for(const imageUrl of chapterInfo.groups[id]) {
const image = await getPage(
chapterInfo.folder,
Object.keys(chapterInfo.groups)[0],
imageUrl
);
images.push(image);
}
return images;
}
// link = getInfo().cover
export function getCover(link) {
return new Promise((resolve, reject) => {
try {
fetch(
`https://guya.moe${link}`
).then(
response => response.buffer()
).then(buffer =>
resolve(buffer.toString("base64"))
);
} catch (err) {
reject(err);
}
});
}
export async function getInfo() {
const response = await fetch(`https://guya.moe/api/series/Kaguya-Wants-To-Be-Confessed-To`);
return response.json(); // returns object
}