From ffc864fe96a3c3117a92d8462010c8413117248a Mon Sep 17 00:00:00 2001 From: NK Date: Wed, 1 Mar 2023 20:59:47 +0000 Subject: [PATCH] skyblock endpoint --- package.json | 3 ++- pages/api/skyblock.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 pages/api/skyblock.js 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"}); + } +}