From 2bc2f3be63081e6fbef94633282e3b5190c9d177 Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Fri, 2 Aug 2024 07:57:18 +0900 Subject: [PATCH] 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 --- lib/games/configureGamePass.js | 42 +++++++++++----------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/lib/games/configureGamePass.js b/lib/games/configureGamePass.js index 9b782c5c..a6f335c6 100644 --- a/lib/games/configureGamePass.js +++ b/lib/games/configureGamePass.js @@ -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 } } } @@ -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}`)) } @@ -88,7 +75,7 @@ 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, @@ -96,15 +83,14 @@ function configureRobux (args, token) { '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, @@ -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) } } })