Merge pull request #100 from thehairy/dev
Fix showbox scraper for native app
This commit is contained in:
commit
c735ce33a0
|
@ -2,6 +2,7 @@ import CryptoJS from 'crypto-js';
|
||||||
import { customAlphabet } from 'nanoid';
|
import { customAlphabet } from 'nanoid';
|
||||||
|
|
||||||
import type { ScrapeContext } from '@/utils/context';
|
import type { ScrapeContext } from '@/utils/context';
|
||||||
|
import { createSearchParams } from '@/utils/params';
|
||||||
|
|
||||||
import { apiUrls, appId, appKey, key } from './common';
|
import { apiUrls, appId, appKey, key } from './common';
|
||||||
import { encrypt, getVerify } from './crypto';
|
import { encrypt, getVerify } from './crypto';
|
||||||
|
@ -34,13 +35,14 @@ export const sendRequest = async (ctx: ScrapeContext, data: object, altApi = fal
|
||||||
});
|
});
|
||||||
const base64body = btoa(body);
|
const base64body = btoa(body);
|
||||||
|
|
||||||
const formatted = new URLSearchParams();
|
const formatted = {
|
||||||
formatted.append('data', base64body);
|
data: base64body,
|
||||||
formatted.append('appid', '27');
|
appid: '27',
|
||||||
formatted.append('platform', 'android');
|
platform: 'android',
|
||||||
formatted.append('version', '129');
|
version: '129',
|
||||||
formatted.append('medium', 'Website');
|
medium: 'Website',
|
||||||
formatted.append('token', randomId(32));
|
token: randomId(32),
|
||||||
|
};
|
||||||
|
|
||||||
const requestUrl = altApi ? apiUrls[1] : apiUrls[0];
|
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',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
'User-Agent': 'okhttp/3.2.0',
|
'User-Agent': 'okhttp/3.2.0',
|
||||||
},
|
},
|
||||||
body: formatted,
|
body: createSearchParams(formatted),
|
||||||
});
|
});
|
||||||
return JSON.parse(response);
|
return JSON.parse(response);
|
||||||
};
|
};
|
||||||
|
|
|
@ -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('&');
|
||||||
|
}
|
Loading…
Reference in New Issue