Skip to content

Commit

Permalink
fix(api/item): leaves not working
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckySoLucky committed Nov 24, 2024
1 parent f3e5e7c commit f0a7526
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/lib/constants/rift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const RIFT_TIMECHARMS = [
{
name: "Supreme Timecharm",
id: "wyldly_supreme",
texture: "/api/item/SPRUCE_LEAVES"
texture: "/api/item/LEAVES:1"
},
{
name: "mrahcemiT esrevrorriM",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/helper/item.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as constants from "../constants/constants";
import type { DatabaseItem, Item, ItemQuery } from "$types/stats";
import sanitize from "mongo-sanitize";
import * as constants from "../constants/constants";
import * as helper from "../helper";
import type { DatabaseItem, Item, ItemQuery } from "$types/stats";

/**
* Gathers Item Data visualized similarily to in-game NBT format based on a query
Expand Down
3 changes: 2 additions & 1 deletion src/lib/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import fs from "fs-extra";
import sanitize from "mongo-sanitize";
import path from "path";

import type { ItemQuery } from "$types/global";
import minecraftData from "minecraft-data";
import * as helper from "./helper";
import { getItemData } from "./helper/item";
Expand Down Expand Up @@ -442,7 +443,7 @@ async function renderPotion(type: string, color: string) {
* @param {object} query
* @returns Image of an item
*/
export async function renderItem(skyblockId: string | undefined, query: SkyBlockItemQuery): Promise<RenderItemOutput> {
export async function renderItem(skyblockId: string | undefined, query: ItemQuery): Promise<RenderItemOutput> {
query = sanitize(query);
let itemQuery = query ?? {};

Expand Down
5 changes: 3 additions & 2 deletions src/routes/api/item/[id=itemId]/+server.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { RequestHandler } from "./$types";
import { renderItem } from "$lib/renderer";
import { error } from "@sveltejs/kit";
import type { RequestHandler } from "./$types";

// GET /api/head/[id=itemId]
export const GET: RequestHandler = async ({ params }) => {
const { id } = params;

try {
const attachment = await renderItem(id, {});
const damage = parseInt(id.split(":")?.at(-1) ?? "");
const attachment = await renderItem(id, { damage: isNaN(damage) ? 0 : damage });

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

0 comments on commit f0a7526

Please sign in to comment.