Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix configureGamePass #813

Merged
merged 7 commits into from
Aug 1, 2024
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 13 additions & 28 deletions lib/games/configureGamePass.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,20 @@ exports.optional = ['description', 'price', 'icon', 'jar']
// Define
function configureGamePass (gamePassId, name, description, price, icon, jar, token) {
return new Promise((resolve, reject) => {
const file = icon && {
value: icon,
options: {
filename: 'icon.png',
contentType: 'image/png'
}
}

const httpOpt = {
url: '//www.roblox.com/game-pass/update',
url: `//apis.roblox.com/game-passes/v1/game-passes/${gamePassId}/details`,
options: {
method: 'POST',
jar,
headers: {
'X-CSRF-TOKEN': token,
'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryKMFaNaAn4j7XeMO'
'Content-Type': 'multipart/form-data; boundary=-----------------------------205723423134616457963583450846'
Regalijan marked this conversation as resolved.
Show resolved Hide resolved
},
resolveWithFullResponse: true,
formData: {
id: gamePassId,
name,
description,
file
Name: name,
Description: description,
File: icon
}
}
}
Expand All @@ -62,21 +53,18 @@ function configureGamePass (gamePassId, name, description, price, icon, jar, tok
}

return http(httpOpt).then(function (res) {
const json = JSON.parse(res.body)
if (json.isValid) {
if (res.statusCode === 200) {
resolve({
gamePassId,
name,
description: description || '',
...price,
iconChanged: !!file // Boolean Cast
iconChanged: !!icon // Boolean Cast
})
} else {
const priceComment = (typeof (price) === 'number') ? ` | NOTE: Price has successfully been changed to ${price}R.` : ''
if (res.statusCode === 403) {
reject(new Error(`You do not have permission to edit this game pass.${priceComment}`))
} else if (json.error) {
reject(new Error(json.error + priceComment)) // 'The name or description contains inappropriate text.' or 'Text filtering service is unavailable at this time.'
} else {
reject(new Error(`An unexpected error occurred with status code ${res.statusCode}.${priceComment}`))
}
Expand All @@ -88,23 +76,22 @@ function configureGamePass (gamePassId, name, description, price, icon, jar, tok
// Configuring the name/description and Robux must be done in separate calls, albeit to the same end-point.
function configureRobux (args, token) {
const httpOpt = {
url: '//www.roblox.com/game-pass/update',
url: `//apis.roblox.com/game-passes/v1/game-passes/${args.gamePassId}/details`,
options: {
method: 'POST',
jar: args.jar,
headers: {
'X-CSRF-TOKEN': token
},
resolveWithFullResponse: true,
json: {
id: args.gamePassId,
price: Math.floor(args.price || 0), // Prevent Decimals
isForSale: !!Math.max(args.price, 0) // Boolean Cast
formData: {
IsForSale: (!!Math.max(args.price, 0)).toString(), // Boolean Cast
Price: Math.floor(args.price || 0).toString() // Prevent Decimals
}
}
}
return http(httpOpt).then(function (res) {
if (res.body.isValid) {
if (res.statusCode === 200) {
// Passing price as an object, so they can be omitted if configureRobux is not run.
return configureGamePass(
args.gamePassId,
Expand All @@ -121,10 +108,8 @@ function configureRobux (args, token) {
} else {
if (res.statusCode === 403) {
throw new Error('You do not have permission to edit this game pass.')
} else if (res.body.error) {
throw new Error(res.body.error)
} else {
throw new Error(`An unexpected error occurred with status code ${res.statusCode}.`)
throw new Error(res.body.errors || 'An unknown error occurred with status code ' + res.statusCode)
}
}
})
Expand Down
Loading