This repository was archived by the owner on Aug 20, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathroutes.js
More file actions
92 lines (90 loc) · 5.07 KB
/
Copy pathroutes.js
File metadata and controls
92 lines (90 loc) · 5.07 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
const axios = require('axios');
let characters = ["taiga", "ryuuji", "ami", "minori", "yasuko", "kitamura", "sumire", "nanako", "sakura", "kota", "koji", "maya", "yuri", "inko"];
let appRouter = function(app) {
app.get("/", async (_req, res) => {
res.send({"status": "error", "code": "-1", "message": "page work in progress. use /api/v1/ to use the api"});
});
app.get("/api", async (_req, res) => {
res.send({"status": "error", "code": "0", "message": "no api version specified"});
});
app.get("/api/v1", async (_req, res) => {
res.send({"status": "error", "code": "1", "message": "no method specified. following methods ara available: /img_original/:character/, /img_fanart/:character"});
});
app.get("/api/v1/img_original", async (_req, res) => {
res.send({"status": "error", "code": "2", "message": "no argument specified. use /img_original/:character"});
});
app.get("/api/v1/img_fanart", async (_req, res) => {
res.send({"status": "error", "code": "2", "message": "no argument specified. use /img_fanart/:character"});
});
app.get("/api/v1/img_original/:character", async (req, res) => {
if(characters.includes(req.params.character)) {
axios.get("https://toradorapi.github.io/images/original/" + req.params.character + ".json").then((response) => {
if(response.data.length > 0) {
let json = response.data[Math.floor(Math.random()*response.data.length)];
json.status = "success";
res.send(json);
} else {
res.send({"status": "error", "code": "4", "message": "there are currently no images for this character."});
}
});
} else if(req.params.character === "all") {
res.send({"status": "error", "code": "5", "message": "this feature is still to be developed."});
} else {
res.send({"status": "error", "code": "3", "message": "we weren't able to find this character. all character available are: " + characters.join(", ")});
}
});
app.get("/api/v1/img_original/:character/list", async (req, res) => {
if(characters.includes(req.params.character)) {
axios.get("https://toradorapi.github.io/images/original/" + req.params.character + ".json").then((response) => {
if(response.data.length > 0) {
let json = {};
json.status = "success";
json.list = response.data
res.send(json);
} else {
res.send({"status": "error", "code": "4", "message": "there are currently no images for this character."});
}
});
} else if(req.params.character === "all") {
res.send({"status": "error", "code": "5", "message": "this feature is still to be developed."});
} else {
res.send({"status": "error", "code": "3", "message": "we weren't able to find this character. all character available are: " + characters.join(", ")});
}
});
app.get("/api/v1/img_fanart/:character", async (req, res) => {
if(characters.includes(req.params.character)) {
axios.get("https://toradorapi.github.io/images/fanart/" + req.params.character + ".json").then((response) => {
if(response.data.length > 0) {
let json = response.data[Math.floor(Math.random()*response.data.length)];
json.status = "success";
res.send(json);
} else {
res.send({"status": "error", "code": "4", "message": "there are currently no images for this character."});
}
});
} else if(req.params.character === "all") {
res.send({"status": "error", "code": "5", "message": "this feature is still to be developed."});
} else {
res.send({"status": "error", "code": "3", "message": "we weren't able to find this character. all character available are: " + characters.join(", ")});
}
});
app.get("/api/v1/img_fanart/:character/list", async (req, res) => {
if(characters.includes(req.params.character)) {
axios.get("https://toradorapi.github.io/images/fanart/" + req.params.character + ".json").then((response) => {
if(response.data.length > 0) {
let json = {};
json.status = "success";
json.list = response.data
res.send(json);
} else {
res.send({"status": "error", "code": "4", "message": "there are currently no images for this character."});
}
});
} else if(req.params.character === "all") {
res.send({"status": "error", "code": "5", "message": "this feature is still to be developed."});
} else {
res.send({"status": "error", "code": "3", "message": "we weren't able to find this character. all character available are: " + characters.join(", ")});
}
});
};
module.exports = appRouter;