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!
This commit is contained in:
Emi Matchu 2023-08-29 14:40:59 -07:00
parent 85d68f68e1
commit 80428e9834
2 changed files with 11 additions and 13 deletions

View file

@ -56,8 +56,7 @@
"sharp": "^0.29.2", "sharp": "^0.29.2",
"simple-markdown": "^0.7.2", "simple-markdown": "^0.7.2",
"tweenjs": "^1.0.2", "tweenjs": "^1.0.2",
"typescript": "^4.4.4", "typescript": "^4.4.4"
"xmlrpc": "^1.3.2"
}, },
"scripts": { "scripts": {
"prepare": "husky install", "prepare": "husky install",

View file

@ -1,23 +1,22 @@
import util from "util";
import fetch from "node-fetch"; import fetch from "node-fetch";
import xmlrpc from "xmlrpc";
const neopetsXmlrpcClient = xmlrpc.createSecureClient({ async function neopetsAmfphpCall(methodName, args) {
host: "www.neopets.com", const url =
path: "/amfphp/xmlrpc.php", "https://www.neopets.com/amfphp/json.php/" +
}); encodeURIComponent(methodName) +
const neopetsXmlrpcCall = util "/" +
.promisify(neopetsXmlrpcClient.methodCall) args.map(encodeURIComponent).join("/");
.bind(neopetsXmlrpcClient); return await fetch(url).then((res) => res.json());
}
export async function loadPetMetaData(petName) { export async function loadPetMetaData(petName) {
const response = await neopetsXmlrpcCall("PetService.getPet", [petName]); const response = await neopetsAmfphpCall("PetService.getPet", [petName]);
return response; return response;
} }
export async function loadCustomPetData(petName) { export async function loadCustomPetData(petName) {
try { try {
const response = await neopetsXmlrpcCall("CustomPetService.getViewerData", [ const response = await neopetsAmfphpCall("CustomPetService.getViewerData", [
petName, petName,
]); ]);
return response; return response;