-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
88 lines (75 loc) · 2.42 KB
/
index.ts
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
import { opine } from "https://x.nest.land/[email protected]/mod.ts";
try {
Deno.lstatSync("./bigrat.monster").isDirectory;
} catch (_) {
await Deno.run({
cmd: ["git", "clone", "https://github.com/bigratmonster/bigrat.monster"],
}).status();
}
const app = opine();
const port = 8080;
const monkeys: string[] = [];
const deepfakes: string[] = [];
const other: string[] = [];
for await (const file of Deno.readDir("./bigrat.monster/media/monkeys/")) {
monkeys.push(file.name);
}
for await (const file of Deno.readDir("./bigrat.monster/media/deepfakes/")) {
deepfakes.push(file.name);
}
for await (const file of Deno.readDir("./bigrat.monster/media/")) {
other.push(file.name);
}
app.get("/random", (req, res) => {
switch (req.query.category) {
case "monkey":
res.sendFile(monkeys[Math.floor(Math.random() * monkeys.length)], {
root: "./bigrat.monster/media/monkeys/",
});
break;
case "deepfake":
res.sendFile(deepfakes[Math.floor(Math.random() * deepfakes.length)], {
root: "./bigrat.monster/media/deepfakes/",
});
break;
case "other":
res.sendFile(other[Math.floor(Math.random() * deepfakes.length)], {
root: "./bigrat.monster/media/",
});
break;
default:
res.send(
"<script>window.location.href = 'https://www.youtube.com/watch?v=HUgMWJKn2YY'</script><noscript><a href='https://www.youtube.com/watch?v=HUgMWJKn2YY' style='font-family: monospace'>404</a></noscript>",
);
break;
}
});
app.get("/freekr", (_, res) => {
res.sendFile("index.html", { root: "./bigrat.monster/freekr/" });
});
app.get("/facts", (_, res) => {
res.sendFile("index.html", { root: "./bigrat.monster/facts/" });
});
app.get("/facts", (_, res) => {
res.sendFile("index.html", { root: "./bigrat.monster/facts/" });
});
app.get("/printer", (_, res) => {
res.sendFile("index.html", { root: "./bigrat.monster/printer/" });
});
app.get("/quiz", (_, res) => {
res.sendFile("index.html", { root: "./bigrat.monster/quiz/" });
});
app.get("/", (_, res) => {
res.send(`
<pre>GET /random?category=[monkey | deepfake | other]</pre><pre>GET /freekr</pre>
<pre>GET /facts</pre>
<pre>GET /printer</pre>
<pre>GET /quiz</pre>`.trimStart());
});
app.use((_, res) => {
res.sendStatus(404);
res.sendFile("404.html", { root: "./bigrat.monster" });
});
app.listen(port, () => {
console.log(`Bigrat.monster API listening at http://localhost:${port}`);
});