This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
115 lines (94 loc) · 2.38 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
const express = require("express");
const cors = require("cors");
const axios = require("axios");
const colors = require("ansi-colors");
const path = require("path");
const app = express();
const PORT = 8080;
app.use(cors());
const isImageUrl = (url) => {
const imageFormats = [".jpg", ".jpeg", ".png", ".gif"];
const lowerCaseUrl = url.toLowerCase();
return imageFormats.some((format) => lowerCaseUrl.endsWith(format));
};
app.get("/", (req, res) => {
const filePath = path.join(__dirname, "docs.html");
res.sendFile(filePath);
});
//Anime
app.get("/animeme", async (req, res) => {
try {
const response = await axios.get(
"https://www.reddit.com/r/Animemes/random/.json"
);
const data = response.data;
if (
data &&
data[0] &&
data[0].data &&
data[0].data.children &&
data[0].data.children.length > 0
) {
const aniMeme = data[0].data.children[0].data;
if (aniMeme.thumbnail && aniMeme.title && isImageUrl(aniMeme.url)) {
const meme = {
title: aniMeme.title,
url: aniMeme.url,
};
res.json(meme);
} else {
res.status(500).json({
error: "Failed to fetch meme",
});
}
} else {
res.status(500).json({
error: "Failed to fetch meme",
});
}
} catch (error) {
res.status(500).json({
error: "Failed to fetch meme",
});
}
});
//Hentai
app.get("/henmeme", async (req, res) => {
try {
const response = await axios.get(
"https://www.reddit.com/r/Hentaimemes/random/.json"
);
const data = response.data;
if (
data &&
data[0] &&
data[0].data &&
data[0].data.children &&
data[0].data.children.length > 0
) {
const aniMeme = data[0].data.children[0].data;
if (aniMeme.thumbnail && aniMeme.title && isImageUrl(aniMeme.url)) {
const meme = {
title: aniMeme.title,
url: aniMeme.url,
};
res.json(meme);
} else {
res.status(500).json({
error: "Failed to fetch meme",
});
}
} else {
res.status(500).json({
error: "Failed to fetch meme",
});
}
} catch (error) {
res.status(500).json({
error: "Failed to fetch meme",
});
}
});
app.listen(PORT, () =>
console.log(`\n> API is 🔥 at : ${colors.blue(`https://localhost:${PORT}`)}`)
);