-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.mjs
191 lines (183 loc) · 4.14 KB
/
helpers.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
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
190
191
export const hasDigitalArtList = [
"2-Moon Jelly",
"30's Milkman",
"AiMbot-3940",
"Alieums",
"Anhybite",
"B.F. Bugleberry",
"Baghost",
"Baroot",
"Bat Boy",
"Batter Up!",
"Beelt",
"Biogator",
"Birthday Basher",
"Bittersweet Peaks",
"Blademaus",
"Bobbin",
"Bonus Luck",
"Bottled Nightmare",
"Brightlight Casino",
"Byeah Beast",
"Byeah Prime",
"Card Back",
"Carl Griffinsteed",
"Carnival Kingdom",
"Cauldrosaur",
"Chromanova",
"Cloud King",
"Cloudtop Observatory",
"Connival",
"Coral Shoal",
"Crabcha",
"Dance-Off",
"Demon Lord Zeraxos",
"Dig Dog",
"Double or Nothing",
"Dragossum",
"Dream-Eater Bat",
"Dredgelord",
"Droplganger",
"Dunk Tank",
"Dustbunny",
"Eat It Up!",
"Encouraging Cheer",
"Exbeelosion",
"Excavate",
"Fleech",
"Forgotten Tableau",
"Fretzel",
"Friendtriloquist",
"Frog Slap",
"Gachatron",
"Game Wipe",
"Giant Enemy Spider",
"Glow Angel",
"Glowing Cavern",
"Glueman",
"Gourmander",
"Grandpa",
"Greedy Grinner",
"Green Screen",
"Harlefin",
"Highland Destrier",
"Hydraxolotl",
"Hypnodaze",
"Intimidate",
"Invasive Wavestrider",
"JBA Power Card: Upgrade",
"Jerma Earth",
"Jerma Moon",
"Jerma Pluto",
"Jerma",
"Jestapod",
"JEX",
"Jukeboxer",
"Jup the 2nd",
"Kelpdrake Root",
"Launch Card",
"Lavabrys Shark",
"Lizard Wizard",
"Lobboss",
"Meowdy",
"Minereel",
"Moosaic",
"Mountidary",
"Mr. Anycard",
"Mr. Greenz",
"Nebula Ray",
"Nightmite",
"Nyxwing",
"One Guy",
"Open Geode",
"Optimal Illusion",
"Otto",
"Peep-Peep",
"Pirouette",
"Ponderer's Grove",
"Pourcelain",
"Protojammer",
"Pteroducktyl",
"Puddle Puppy",
"Razzleposs",
"Reorganize",
"Rich Rat",
"Rumble Ring",
"Rummage Rat",
"Scritchy Scratch",
"Seasprinter",
"Serachime",
"Sheetopillar",
"Sludge",
"Small Enemy Spider",
"Snaptrap",
"Sneaky Rat",
"Sneezie",
"Song of Protection",
"Spectocular",
"Starbit Cluster",
"Stormplaty",
"Strong Rat",
"Surprise Snack",
"Sus Guy",
"Sweet Tooth",
"Tactical Rocket Launcher",
"Tadpal",
"The Big Baker",
"The Cauldron",
"The Giant Rat",
"Thingamachicken",
"Toadstool",
"Top Rope",
"Volca Isle",
"Wall Dad",
];
export function cardNameToCardImageURL(cardName, getScan = false) {
if (cardName === null || cardName === undefined) {
return null;
}
const fixedName = cardName
.replaceAll("+", "%2B")
.replaceAll("ñ", "n")
if (hasDigitalArtList.includes(cardName) && !getScan) {
return "https://www.grotto-bestiary.com/images/digital-cards/" + fixedName.replaceAll(" ", "%20") + ".jpg";
} else {
return "https://grotto-beast-cards-images.s3.us-east-2.amazonaws.com/" + fixedName.replaceAll(" ", "+") + ".webp";
}
}
export function cardNameToCardDetailsURL(cardName) {
if (cardName === null || cardName === undefined) {
return null;
}
return (
"http://grotto-bestiary.com/card-details?cardName=" +
cardName
.replaceAll("+", "%2B")
.replaceAll("ñ", "n")
.replaceAll(" ", "+")
);
}
export function getHostFromReq(req) {
let uri = `${req.protocol}://${req.get("host")}/`;
uri = uri.replace("localhost:5000", "localhost:3000");
if (process.env.CODESPACES) {
uri = `https://${process.env.CODESPACE_NAME}-3000.app.github.dev/`;
}
return uri;
}
export async function checkLogin(req, res, next) {
try {
//Check that user is logged in
if (typeof req.session?.user?.id !== "string") {
res.status(401).send({
error: "Unauthorized",
error_message: "You must be logged in to change your inventory.",
});
return;
}
next();
} catch (e) {
console.error(e);
res.status(500).send({ error: "Internal Server Error" });
}
};