diff --git a/package.json b/package.json index 6ebfca4..894547d 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "next-auth": "^3.27.0", "react": "^17.0.2", "react-dom": "^17.0.2", - "react-icons": "^4.2.0" + "react-icons": "^4.2.0", + "skyhelper-networth": "^1.11.5" }, "devDependencies": { "eslint": "^8.2.0", diff --git a/pages/api/skyblock.js b/pages/api/skyblock.js new file mode 100644 index 0000000..83f00bb --- /dev/null +++ b/pages/api/skyblock.js @@ -0,0 +1,21 @@ +const {getItemNetworth} = require("skyhelper-networth"); +const nbt = require("prismarine-nbt"); +const parseNbt = require("util").promisify(nbt.parse); +async function decodeData(buffer) { + const parsedNbt = await parseNbt(Buffer.from(buffer, "base64")); + return nbt.simplify(parsedNbt); +} + +export default async function handler(req, res) { + if (req.method == "GET") { + const {ByteData} = JSON.parse(req.body); + if (ByteData == undefined) + res.status(400).json({error: "ByteData is undefined"}); + const data = await getItemNetworth((await decodeData(ByteData)).i[0], { + cache: true, + }); + res.status(200).json(data); + } else { + res.status(400).json({error: "This endpoint only accepts GET requests"}); + } +}