From 80428e983430506650133173252ad5ab2a503115 Mon Sep 17 00:00:00 2001 From: Matchu Date: Tue, 29 Aug 2023 14:40:59 -0700 Subject: [PATCH] Fix pet loading for most pets Sigh, I guess xmlrpc was deleted? Back to the method that doesn't work for pets with leading digits in their names, sobbe Dice has a neat idea for how to work around that, but I'm not sure how to fit it in our architecture, let's take a look! --- package.json | 3 +-- src/server/load-pet-data.js | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 5901f7d..4616406 100644 --- a/package.json +++ b/package.json @@ -56,8 +56,7 @@ "sharp": "^0.29.2", "simple-markdown": "^0.7.2", "tweenjs": "^1.0.2", - "typescript": "^4.4.4", - "xmlrpc": "^1.3.2" + "typescript": "^4.4.4" }, "scripts": { "prepare": "husky install", diff --git a/src/server/load-pet-data.js b/src/server/load-pet-data.js index c8db65c..bb520ab 100644 --- a/src/server/load-pet-data.js +++ b/src/server/load-pet-data.js @@ -1,23 +1,22 @@ -import util from "util"; import fetch from "node-fetch"; -import xmlrpc from "xmlrpc"; -const neopetsXmlrpcClient = xmlrpc.createSecureClient({ - host: "www.neopets.com", - path: "/amfphp/xmlrpc.php", -}); -const neopetsXmlrpcCall = util - .promisify(neopetsXmlrpcClient.methodCall) - .bind(neopetsXmlrpcClient); +async function neopetsAmfphpCall(methodName, args) { + const url = + "https://www.neopets.com/amfphp/json.php/" + + encodeURIComponent(methodName) + + "/" + + args.map(encodeURIComponent).join("/"); + return await fetch(url).then((res) => res.json()); +} export async function loadPetMetaData(petName) { - const response = await neopetsXmlrpcCall("PetService.getPet", [petName]); + const response = await neopetsAmfphpCall("PetService.getPet", [petName]); return response; } export async function loadCustomPetData(petName) { try { - const response = await neopetsXmlrpcCall("CustomPetService.getViewerData", [ + const response = await neopetsAmfphpCall("CustomPetService.getViewerData", [ petName, ]); return response;