Skip to content

Commit

Permalink
fix(api/potion): regex
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckySoLucky committed Dec 15, 2024
1 parent c34245c commit 2867860
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib/server/constants/skills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export const SKILL_ICONS = {
carpentry: "/api/item/CRAFTING_TABLE",
social: "/api/item/EMERALD",
dungeoneering: "/api/head/964e1c3e315c8d8fffc37985b6681c5bd16a6f97ffd07199e8a05efbef103793",
healer: "/api/potion/normal/10",
healer: "/api/potion/normal/2",
mage: "/api/item/BLAZE_ROD",
archer: "/api/item/BOW",
berserk: "/api/item/IRON_SWORD",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/shared/constants/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const POTION_COLORS = {
13: "2f549c", // Water Breathing
14: "818595", // Invisibility
15: "f500f5" // Uncraftable
};
} as Record<string, string>;

export const TYPE_TO_CATEGORIES = {
helmet: ["armor", "helmet"],
Expand Down
7 changes: 7 additions & 0 deletions src/params/potionColor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { ParamMatcher } from "@sveltejs/kit";

export const isPotionColor = ((param) => {
return typeof param === "string" && parseInt(param) >= 0 && parseInt(param) <= 15;
}) satisfies ParamMatcher;

export const match = isPotionColor;
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { POTION_COLORS } from "$constants/constants";
import { getPotion } from "$lib/renderer";
import type { RequestHandler } from "./$types";
import { error } from "@sveltejs/kit";
import type { RequestHandler } from "./$types";

export const GET: RequestHandler = async ({ params }) => {
const { type, color } = params;

const potionColor = POTION_COLORS[color];

try {
const attachment = await getPotion(type, color);
const attachment = await getPotion(type, potionColor);

return new Response(attachment, { headers: { "Content-Type": "image/png" } });
} catch (errorMsg) {
Expand Down

0 comments on commit 2867860

Please sign in to comment.