Skip to content

Commit 2bc2f3b

Browse files
authored
Fix configureGamePass (#813)
* 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
1 parent c515503 commit 2bc2f3b

File tree

1 file changed

+13
-29
lines changed

1 file changed

+13
-29
lines changed

lib/games/configureGamePass.js

+13-29
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,19 @@ exports.optional = ['description', 'price', 'icon', 'jar']
2626
// Define
2727
function configureGamePass (gamePassId, name, description, price, icon, jar, token) {
2828
return new Promise((resolve, reject) => {
29-
const file = icon && {
30-
value: icon,
31-
options: {
32-
filename: 'icon.png',
33-
contentType: 'image/png'
34-
}
35-
}
36-
3729
const httpOpt = {
38-
url: '//www.roblox.com/game-pass/update',
30+
url: `//apis.roblox.com/game-passes/v1/game-passes/${gamePassId}/details`,
3931
options: {
4032
method: 'POST',
4133
jar,
4234
headers: {
43-
'X-CSRF-TOKEN': token,
44-
'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryKMFaNaAn4j7XeMO'
35+
'X-CSRF-TOKEN': token
4536
},
4637
resolveWithFullResponse: true,
4738
formData: {
48-
id: gamePassId,
49-
name,
50-
description,
51-
file
39+
Name: name,
40+
Description: description,
41+
File: icon
5242
}
5343
}
5444
}
@@ -62,21 +52,18 @@ function configureGamePass (gamePassId, name, description, price, icon, jar, tok
6252
}
6353

6454
return http(httpOpt).then(function (res) {
65-
const json = JSON.parse(res.body)
66-
if (json.isValid) {
55+
if (res.statusCode === 200) {
6756
resolve({
6857
gamePassId,
6958
name,
7059
description: description || '',
7160
...price,
72-
iconChanged: !!file // Boolean Cast
61+
iconChanged: !!icon // Boolean Cast
7362
})
7463
} else {
7564
const priceComment = (typeof (price) === 'number') ? ` | NOTE: Price has successfully been changed to ${price}R.` : ''
7665
if (res.statusCode === 403) {
7766
reject(new Error(`You do not have permission to edit this game pass.${priceComment}`))
78-
} else if (json.error) {
79-
reject(new Error(json.error + priceComment)) // 'The name or description contains inappropriate text.' or 'Text filtering service is unavailable at this time.'
8067
} else {
8168
reject(new Error(`An unexpected error occurred with status code ${res.statusCode}.${priceComment}`))
8269
}
@@ -88,23 +75,22 @@ function configureGamePass (gamePassId, name, description, price, icon, jar, tok
8875
// Configuring the name/description and Robux must be done in separate calls, albeit to the same end-point.
8976
function configureRobux (args, token) {
9077
const httpOpt = {
91-
url: '//www.roblox.com/game-pass/update',
78+
url: `//apis.roblox.com/game-passes/v1/game-passes/${args.gamePassId}/details`,
9279
options: {
9380
method: 'POST',
9481
jar: args.jar,
9582
headers: {
9683
'X-CSRF-TOKEN': token
9784
},
9885
resolveWithFullResponse: true,
99-
json: {
100-
id: args.gamePassId,
101-
price: Math.floor(args.price || 0), // Prevent Decimals
102-
isForSale: !!Math.max(args.price, 0) // Boolean Cast
86+
formData: {
87+
IsForSale: (!!Math.max(args.price, 0)).toString(), // Boolean Cast
88+
Price: Math.floor(args.price || 0).toString() // Prevent Decimals
10389
}
10490
}
10591
}
10692
return http(httpOpt).then(function (res) {
107-
if (res.body.isValid) {
93+
if (res.statusCode === 200) {
10894
// Passing price as an object, so they can be omitted if configureRobux is not run.
10995
return configureGamePass(
11096
args.gamePassId,
@@ -121,10 +107,8 @@ function configureRobux (args, token) {
121107
} else {
122108
if (res.statusCode === 403) {
123109
throw new Error('You do not have permission to edit this game pass.')
124-
} else if (res.body.error) {
125-
throw new Error(res.body.error)
126110
} else {
127-
throw new Error(`An unexpected error occurred with status code ${res.statusCode}.`)
111+
throw new Error(res.body.errors || 'An unknown error occurred with status code ' + res.statusCode)
128112
}
129113
}
130114
})

0 commit comments

Comments
 (0)