move showbox fix to util function

This commit is contained in:
thehairy
2024-02-27 22:26:43 +01:00
parent 85cb751542
commit f47a2b0f40
2 changed files with 13 additions and 7 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';
@@ -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);
};

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