Skip to content

Commit

Permalink
fix: /item not being able to return vanilla item (#1952)
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckySoLucky authored Jun 20, 2023
1 parent ff19a95 commit 71fc095
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
12 changes: 4 additions & 8 deletions src/helper/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import sanitize from "mongo-sanitize";
* @returns {*} Item Data
*/
export async function getItemData(query = {}) {
query = Object.assign({ skyblockId: undefined, id: undefined, name: undefined, damage: undefined }, query);
query = Object.assign({ skyblockId: undefined, id: undefined, name: undefined, Damage: undefined }, query);
const item = { id: -1, damage: 0, Count: 1, tag: { ExtraAttributes: {} } };
let dbItem = {};

/**
* Look for DB items if possible with Skyblock ID or query name
*/
if (query.skyblockId !== undefined) {
if (query.skyblockId !== undefined && query.skyblockId !== null) {
query.skyblockId = sanitize(query.skyblockId);

if (query.skyblockId.includes(":")) {
Expand All @@ -28,7 +28,7 @@ export async function getItemData(query = {}) {
query.damage = new Number(split[1]);
}

dbItem = (await db.collection("items").findOne({ id: query.skyblockId })) ?? {};
dbItem = Object.assign(item, await db.collection("items").findOne({ id: query.skyblockId }));
}

if (query.name !== undefined) {
Expand All @@ -48,10 +48,6 @@ export async function getItemData(query = {}) {
item.id = query.id;
}

if (query.damage !== undefined) {
item.Damage = query.damage;
}

if (query.name !== undefined) {
item.tag.display = { Name: query.name };
}
Expand All @@ -61,7 +57,7 @@ export async function getItemData(query = {}) {
}

if ("damage" in dbItem) {
item.damage = dbItem.damage;
item.Damage = query.damage ?? dbItem.damage;
}

if ("name" in dbItem) {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ export async function renderItem(skyblockId, query) {
itemQuery = Object.assign(query, { skyblockId });
}

const item = await getItemData(itemQuery);
const item = await getItemData({ skyblockId, ...itemQuery });
const outputTexture = { mime: "image/png" };

for (const rule of itemsCss.stylesheet.rules) {
Expand Down
6 changes: 2 additions & 4 deletions src/routes/item.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import cors from "cors";
import express from "express";

import { db } from "../mongo.js";

import * as app from "../app.js";
import * as helper from "../helper.js";
import * as renderer from "../renderer.js";
Expand All @@ -12,12 +10,12 @@ router.use(cors());

router.all("/:itemId?", cors(), async (req, res, next) => {
try {
const itemId = req.params.itemId?.toUpperCase() || null;
const itemId = req.params.itemId || null;
if (!req.query.pack && req.cookies.pack) {
req.query.pack = req.cookies.pack;
}

const item = await renderer.renderItem(itemId, req.query, db);
const item = await renderer.renderItem(itemId, req.query);

if (item.error) {
throw new Error(item.error);
Expand Down

0 comments on commit 71fc095

Please sign in to comment.