-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinterstitial.ts
64 lines (59 loc) · 2.47 KB
/
interstitial.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import {parseObject} from "./util";
import {Session} from "../index";
import {sendRequestWithHeaders} from "./api";
/**
* Parses the device check URL (`/interstitial/?initialCid`...) from a blocked response body.
* @param body The response body
* @param cookie The `datadome` cookie value
* @param referer The referer
*/
export function parseInterstitialDeviceCheckUrl(body: string, cookie: string, referer: string): string | null {
const dd = parseObject(body);
if (dd == null) {
return null;
}
const params = {
initialCid: dd.cid,
hash: dd.hsh,
cid: cookie,
referer,
s: dd.hasOwnProperty("s") ? dd.s.toString() : "0",
b: dd.hasOwnProperty("b") ? dd.b.toString() : "0",
dm: "cd"
};
return "https://geo.captcha-delivery.com/interstitial/?" + new URLSearchParams(params).toString();
}
/**
* Interstitial API input.
*/
export class InterstitialInput {
readonly userAgent: string;
readonly deviceLink: string;
readonly html: string;
readonly ip: string;
readonly acceptLanguage: string;
/**
* Creates a new InterstitialInput instance.
* @param userAgent The browser user agent to impersonate.
* @param deviceLink The device check URL obtained from {@link parseInterstitialDeviceCheckUrl}.
* @param html The response body obtained from doing a GET request to the device check URL.
* @param ip The IPV4 address of your network or proxy.
* @param acceptLanguage Your accept-language header.
*/
public constructor(userAgent: string, deviceLink: string, html: string, ip: string, acceptLanguage: string) {
this.userAgent = userAgent;
this.deviceLink = deviceLink;
this.html = html;
this.ip = ip;
this.acceptLanguage = acceptLanguage;
}
}
/**
* Generates a DataDome interstitial payload that can be used to obtain a solved `datadome` cookie.
* @param session The {@link Session}
* @param input The {@link InterstitialInput} containing required parameters for interstitial payload generation
* @returns {Promise<{payload: string, headers: {[key: string]: string}}>} A {@link Promise} that resolves to an object containing the interstitial payload and response headers
*/
export function generateInterstitialPayload(session: Session, input: InterstitialInput): Promise<{ payload: string, headers: { [key: string]: string } }> {
return sendRequestWithHeaders(session, "https://datadome.justhyped.dev/interstitial", input);
}