From 85cb75154290d2a7a10e1b75e6cce3f740811c1d Mon Sep 17 00:00:00 2001 From: thehairy <71461991+thehairy@users.noreply.github.com> Date: Tue, 27 Feb 2024 21:16:32 +0100 Subject: [PATCH 1/2] Update sendRequest.ts --- src/providers/sources/showbox/sendRequest.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/providers/sources/showbox/sendRequest.ts b/src/providers/sources/showbox/sendRequest.ts index 7ea9024..6923a3c 100644 --- a/src/providers/sources/showbox/sendRequest.ts +++ b/src/providers/sources/showbox/sendRequest.ts @@ -34,13 +34,14 @@ export const sendRequest = async (ctx: ScrapeContext, data: object, altApi = fal }); const base64body = btoa(body); - const formatted = new URLSearchParams(); - formatted.append('data', base64body); - formatted.append('appid', '27'); - formatted.append('platform', 'android'); - formatted.append('version', '129'); - formatted.append('medium', 'Website'); - formatted.append('token', randomId(32)); + const formatted = { + 'data': base64body, + 'appid': '27', + 'platform': 'android', + 'version': '129', + 'medium': 'Website', + 'token': randomId(32) + }; const requestUrl = altApi ? apiUrls[1] : apiUrls[0]; @@ -51,7 +52,7 @@ export const sendRequest = async (ctx: ScrapeContext, data: object, altApi = fal 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'okhttp/3.2.0', }, - body: formatted, + body: Object.entries(formatted).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join('&'), }); return JSON.parse(response); }; From f47a2b0f40c5a9bf6a6d596b3d845287fdd9b3be Mon Sep 17 00:00:00 2001 From: thehairy Date: Tue, 27 Feb 2024 22:26:43 +0100 Subject: [PATCH 2/2] move showbox fix to util function --- src/providers/sources/showbox/sendRequest.ts | 15 ++++++++------- src/utils/params.ts | 5 +++++ 2 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 src/utils/params.ts diff --git a/src/providers/sources/showbox/sendRequest.ts b/src/providers/sources/showbox/sendRequest.ts index 6923a3c..248fddd 100644 --- a/src/providers/sources/showbox/sendRequest.ts +++ b/src/providers/sources/showbox/sendRequest.ts @@ -2,6 +2,7 @@ import CryptoJS from 'crypto-js'; import { customAlphabet } from 'nanoid'; import type { ScrapeContext } from '@/utils/context'; +import { createSearchParams } from '@/utils/params'; import { apiUrls, appId, appKey, key } from './common'; import { encrypt, getVerify } from './crypto'; @@ -35,12 +36,12 @@ export const sendRequest = async (ctx: ScrapeContext, data: object, altApi = fal const base64body = btoa(body); const formatted = { - 'data': base64body, - 'appid': '27', - 'platform': 'android', - 'version': '129', - 'medium': 'Website', - 'token': randomId(32) + data: base64body, + appid: '27', + platform: 'android', + version: '129', + medium: 'Website', + token: randomId(32), }; const requestUrl = altApi ? apiUrls[1] : apiUrls[0]; @@ -52,7 +53,7 @@ export const sendRequest = async (ctx: ScrapeContext, data: object, altApi = fal 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'okhttp/3.2.0', }, - body: Object.entries(formatted).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join('&'), + body: createSearchParams(formatted), }); return JSON.parse(response); }; diff --git a/src/utils/params.ts b/src/utils/params.ts new file mode 100644 index 0000000..ea2149f --- /dev/null +++ b/src/utils/params.ts @@ -0,0 +1,5 @@ +export function createSearchParams(params: { [key: string]: string | number }): string { + return Object.entries(params) + .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`) + .join('&'); +}