Use non-rate-limited API and improve some stuff

This commit is contained in:
2024-04-15 21:15:35 -05:00
parent 14d57a4561
commit 214790809d
3 changed files with 102 additions and 53 deletions

55
common.js Normal file

@ -0,0 +1,55 @@
const axios = require("axios").default;
// https://create.roblox.com/docs/reference/engine/enums/AssetType
const AssetType = {
Image: 1,
TShirt: 2,
Audio: 3,
Mesh: 4,
Lua: 5,
Hat: 8,
Place: 9,
Model: 10,
Shirt: 11,
Pants: 12,
Decal: 13,
Head: 17,
Face: 18,
Gear: 19,
Badge: 21,
Animation: 24,
GamePass: 34,
Plugin: 38,
MeshPart: 40
};
async function getAssetInfo(assetId) {
const res = await axios.get("https://apis.roblox.com/toolbox-service/v1/items/details", {
params: {
assetIds: assetId
},
validateStatus: (status) => status === 403 || status === 404 || (status >= 200 && status < 300) // Allow 403/404 as a valid status (don't throw an error)
});
if (res.status < 200 || res.status > 300) {
return {
status: res.status
}
}
const data = res.data.data;
const assetInfo = data[0];
return {
status: res.status,
id: assetId,
name: assetInfo.asset.name,
typeId: assetInfo.asset.typeId,
creatorId: assetInfo.creator.id,
price: assetInfo.product.price,
productId: assetInfo.product.productId,
forSale: assetInfo.product.isForSaleOrIsPublicDomain
}
}
module.exports = { AssetType, getAssetInfo };