Merge branch 'master' into disable-verification
This commit is contained in:
79
common.js
79
common.js
@ -1,5 +1,6 @@
|
||||
const axios = require("axios").default;
|
||||
const { RobloxFile } = require("rbxm-parser");
|
||||
const noblox = require("noblox.js");
|
||||
|
||||
// https://create.roblox.com/docs/reference/engine/enums/AssetType
|
||||
const AssetType = {
|
||||
@ -25,44 +26,70 @@ const AssetType = {
|
||||
};
|
||||
|
||||
async function getAssetInfo(assetId) {
|
||||
const res = await axios.get("https://apis.roblox.com/toolbox-service/v1/items/details", {
|
||||
params: {
|
||||
assetIds: assetId
|
||||
},
|
||||
validateStatus: (_status) => true
|
||||
const jar = noblox.options.jar;
|
||||
const xcsrf = await noblox.getGeneralToken(jar);
|
||||
|
||||
const res = await noblox.http(`https://apis.roblox.com/user/cloud/v2/creator-store-products/PRODUCT_NAMESPACE_CREATOR_MARKETPLACE_ASSET-PRODUCT_TYPE_MODEL-${assetId}`, {
|
||||
method: "GET",
|
||||
resolveWithFullResponse: true,
|
||||
jar: jar,
|
||||
headers: {
|
||||
"X-CSRF-TOKEN": xcsrf,
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
});
|
||||
|
||||
if (res.status < 200 || res.status > 300) {
|
||||
if (res.statusCode < 200 || res.statusCode >= 300) {
|
||||
return {
|
||||
status: res.status
|
||||
status: res.statusCode,
|
||||
isModel: false
|
||||
};
|
||||
}
|
||||
|
||||
const data = res.data.data;
|
||||
const assetInfo = data[0];
|
||||
let isFree, forSale;
|
||||
if (assetInfo.fiatProduct) {
|
||||
const quantity = assetInfo.fiatProduct.purchasePrice.quantity;
|
||||
isFree = quantity.significand === 0 && quantity.exponent === 0;
|
||||
forSale = assetInfo.fiatProduct.published && assetInfo.fiatProduct.purchasable;
|
||||
}
|
||||
else {
|
||||
isFree = assetInfo.product.price === 0;
|
||||
forSale = assetInfo.product.isForSaleOrIsPublicDomain;
|
||||
}
|
||||
console.log(assetInfo);
|
||||
const assetInfo = JSON.parse(res.body);
|
||||
const quantity = assetInfo.purchasePrice.quantity;
|
||||
const isFree = quantity.significand === 0 && quantity.exponent === 0;
|
||||
const forSale = assetInfo.published && assetInfo.purchasable;
|
||||
|
||||
return {
|
||||
status: res.status,
|
||||
id: assetId,
|
||||
name: assetInfo.asset.name,
|
||||
typeId: assetInfo.asset.typeId,
|
||||
creatorId: assetInfo.creator.id,
|
||||
status: res.statusCode,
|
||||
isModel: true,
|
||||
id: assetInfo.modelAssetId,
|
||||
creatorId: +assetInfo.userSeller,
|
||||
isFree: isFree,
|
||||
forSale: forSale
|
||||
};
|
||||
}
|
||||
|
||||
async function buyModel(modelId) {
|
||||
const reqJson = {
|
||||
expectedPrice: {currencyCode: "USD", quantity: {significand: 0, exponent: 0}},
|
||||
productKey: {
|
||||
productNamespace: "PRODUCT_NAMESPACE_CREATOR_MARKETPLACE_ASSET",
|
||||
productTargetId: `${modelId}`,
|
||||
productType: "PRODUCT_TYPE_MODEL"
|
||||
}
|
||||
};
|
||||
|
||||
const jar = noblox.options.jar;
|
||||
const xcsrf = await noblox.getGeneralToken(jar);
|
||||
|
||||
const res = await noblox.http("https://apis.roblox.com/marketplace-fiat-service/v1/product/purchase", {
|
||||
method: "POST",
|
||||
resolveWithFullResponse: true,
|
||||
jar: jar,
|
||||
headers: {
|
||||
"X-CSRF-TOKEN": xcsrf,
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(reqJson)
|
||||
});
|
||||
|
||||
const resJson = JSON.parse(res.body);
|
||||
// Return true if purchased, false otherwise
|
||||
return res.statusCode >= 200 && res.statusCode < 300 && resJson.purchaseTransactionStatus === "PURCHASE_TRANSACTION_STATUS_SUCCESS";
|
||||
}
|
||||
|
||||
const SubmissionColumnsString = "map_id,unix_timestamp,user_id,username,display_name,creator\n";
|
||||
|
||||
const SubmissionColumn = {
|
||||
@ -332,4 +359,4 @@ function getValidationMessage(validation, game, errorOnFail) {
|
||||
return msg;
|
||||
}
|
||||
|
||||
module.exports = { AssetType, getAssetInfo, SubmissionColumn, SubmissionColumnsString, getSubmissionLine, createSubmissionLine, validateMapAsset, getValidationMessage, safeCsvFormat };
|
||||
module.exports = { AssetType, getAssetInfo, buyModel, SubmissionColumn, SubmissionColumnsString, getSubmissionLine, createSubmissionLine, validateMapAsset, getValidationMessage, safeCsvFormat };
|
Reference in New Issue
Block a user