This commit is contained in:
NK 2023-03-18 21:27:55 +00:00
parent 614c307618
commit cb7106ff0d

View file

@ -1,4 +1,4 @@
const {getItemNetworth} = require("skyhelper-networth"); const { getItemNetworth } = require("skyhelper-networth");
const nbt = require("prismarine-nbt"); const nbt = require("prismarine-nbt");
const parseNbt = require("util").promisify(nbt.parse); const parseNbt = require("util").promisify(nbt.parse);
async function decodeData(buffer) { async function decodeData(buffer) {
@ -8,13 +8,13 @@ async function decodeData(buffer) {
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == "POST" || req.method == "GET" || req.method == "PUT") { if (req.method == "POST" || req.method == "GET" || req.method == "PUT") {
if (req.body == "") { if (req.body == "") {
res.status(400).json({error: "No body was provided"}); res.status(400).json({ error: "No body was provided" });
return; return;
} }
console.log(req.body); console.log(req.body);
let dat = req.body; let dat = req.body;
if (typeof dat !== "string" || typeof dat == "undefined") { if (typeof dat !== "string" || typeof dat == "undefined") {
res.status(400).json({error: "ByteData is not a string or undefined"}); res.status(400).json({ error: "ByteData is not a string or undefined" });
return; return;
} }
try { try {
@ -23,11 +23,11 @@ export default async function handler(req, res) {
}); });
res.status(200).json(data); res.status(200).json(data);
} catch { } catch {
res.status(400).json({error: "Invalid ByteData"}); res.status(400).json({ error: "Invalid ByteData" });
} }
} else { } else {
res res
.status(400) .status(400)
.json({error: "This endpoint only accepts GET, POST and PUT requests"}); .json({ error: "This endpoint only accepts GET, POST and PUT requests" });
} }
} }