Skip to content

Commit

Permalink
Fix configureGamePass (#813)
Browse files Browse the repository at this point in the history
* Move to new gamepass configuration endpoint

* Stringify non-string/stream form data

* Handle 200 responses correctly

* Actually fix the status code check this time

* Re-add iconChanged property in returned data

* ESLint no like, me fix

* Remove manually specified content-type header
  • Loading branch information
Regalijan authored Aug 1, 2024
1 parent c515503 commit 2bc2f3b
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions lib/games/configureGamePass.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,19 @@ 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'
'X-CSRF-TOKEN': token
},
resolveWithFullResponse: true,
formData: {
id: gamePassId,
name,
description,
file
Name: name,
Description: description,
File: icon
}
}
}
Expand All @@ -62,21 +52,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 +75,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 +107,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

0 comments on commit 2bc2f3b

Please sign in to comment.