Merge pull request #100 from thehairy/dev

Fix showbox scraper for native app
This commit is contained in:
William Oldham 2024-02-29 13:12:03 +00:00 committed by GitHub
commit c735ce33a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 8 deletions

View File

@ -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';
@ -34,13 +35,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 +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: formatted,
body: createSearchParams(formatted),
});
return JSON.parse(response);
};

5
src/utils/params.ts Normal file
View File

@ -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('&');
}