-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
43 lines (36 loc) · 1.09 KB
/
index.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
import axios, { AxiosResponse } from "axios";
import type { BonbastJsonResponse } from "./types";
const api = axios.create({
baseURL: "https://bonbast.com",
headers: {
"User-Agent": Math.random(),
Cookie: "rf_bb=true; st_bb=0",
},
});
const getSourceCode = async (): Promise<string> => {
const { data } = await api.get("/");
return data;
};
const extractToken = (sourceCode: string): string => {
const findBy = `{ data:"`;
const cutBy = `",`;
return sourceCode.split(findBy)[1].split(cutBy)[0];
};
const getExchangeRates = async (
token: string
): Promise<BonbastJsonResponse> => {
var urlencoded = new URLSearchParams();
urlencoded.append("data", token);
urlencoded.append("webdriver", "false");
const { data }: AxiosResponse<BonbastJsonResponse> = await api.post(
"/json",
urlencoded
);
return data;
};
const bonbast = async (): Promise<BonbastJsonResponse> => {
const sourceCode = await getSourceCode();
const token = extractToken(sourceCode);
return await getExchangeRates(token);
};
export default bonbast;