Skip to content

Commit

Permalink
Refactor minion data fetching and update Svelte adapter (#165)
Browse files Browse the repository at this point in the history
Switch to using the Hypixel API for fetching minion data and change the
Svelte adapter from Vercel to Auto, adding the necessary dependency.
  • Loading branch information
DarthGigi authored Feb 6, 2025
2 parents 2e0eb5c + 8c5e9d9 commit 77f51e0
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@eslint/js": "^9.13.0",
"@jill64/universal-sanitizer": "^1.3.3",
"@number-flow/svelte": "^0.3.1",
"@sveltejs/adapter-auto": "^4.0.0",
"@sveltejs/adapter-vercel": "^5.4.6",
"@sveltejs/kit": "^2.7.3",
"@sveltejs/vite-plugin-svelte": "^3.1.2",
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import { json } from "@sveltejs/kit";
import type { RequestHandler } from "./$types";

type Minion = {
[x: string]: any;
material: string;
durability: number;
skin?: {
value: "string";
signature: "string";
};
name: string;
generator: string;
generator_tier: number;
tier: string;
id: string;
};

export const GET: RequestHandler = async () => {
const itemsList = await fetch("https://api.slothpixel.me/api/skyblock/items");
const items = await itemsList.json();
const itemsList = await fetch("https://api.hypixel.net/v2/resources/skyblock/items");
const itemsJson = await itemsList.json();
const items = itemsJson.items;

// convert to array so we can use .filter
const itemsArray = Object.values(items);

// Filter items so that only minions are returned, only minions have generator_tier
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const minions = itemsArray.filter((item: any) => item.generator_tier);
const minions = itemsArray.filter((item: any) => item.generator_tier) as Minion[];

// Sort minions first by name, then by tier so that the order is correct
// eslint-disable-next-line @typescript-eslint/no-explicit-any
minions.sort((a: any, b: any) => {
if (a.name < b.name) return -1;
if (a.name > b.name) return 1;
Expand All @@ -24,6 +38,18 @@ export const GET: RequestHandler = async () => {
return 0;
});

minions.forEach((minion) => {
if (!minion.skin) return;

const skin = JSON.parse(Buffer.from(minion.skin.value, "base64").toString("utf-8"));
const texture = skin.textures.SKIN.url;
const textureId = texture.split("/").pop();

minion.texture = textureId;

delete minion.skin;
});

// give back a .json file
return json(minions);
};
2 changes: 1 addition & 1 deletion svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import adapter from "@sveltejs/adapter-vercel";
import adapter from "@sveltejs/adapter-auto";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";

/** @type {import('@sveltejs/kit').Config} */
Expand Down
3 changes: 1 addition & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export default defineConfig({
sourceMapsUploadOptions: {
org: "minionah",
project: "minionah"
},
adapter: "vercel"
}
}),
sveltekit()
],
Expand Down

0 comments on commit 77f51e0

Please sign in to comment.