forked from szdc/tiktok-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
params.ts
74 lines (71 loc) · 1.52 KB
/
params.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
65
66
67
68
69
70
71
72
73
74
import * as qs from 'qs';
import { ListRequestParams } from './types';
/**
* A map containing the order of the base query string parameters.
*
* @type {Map<string, number>}
*/
export const paramsOrder = [
'app_language',
'language',
'region',
'sys_region',
'carrier_region',
'carrier_region_v2',
'build_number',
'timezone_offset',
'timezone_name',
'mcc_mnc',
'is_my_cn',
'fp',
'account_region',
'pass-region',
'pass-route',
'iid',
'device_id',
'ac',
'channel',
'aid',
'app_name',
'version_code',
'version_name',
'device_platform',
'ssmix',
'device_type',
'device_brand',
'os_api',
'os_version',
'openudid',
'manifest_version_code',
'resolution',
'dpi',
'update_version_code',
'_rticket',
'ts',
'as',
'cp',
'mas',
].reduce((map, param, i) => map.set(param, i), new Map<string, number>());
/**
* Converts a object of parameters into a query string based on the given order.
*/
export const paramsSerializer = (order: Map<string, number>) => (params: object) => qs.stringify(params, {
encode: false,
format: 'RFC1738',
sort: (a: any, b: any) => {
const ai = order.get(a);
const bi = order.get(b);
return (typeof ai === 'undefined' ? -1 : ai) - (typeof bi === 'undefined' ? -1 : bi);
},
});
/**
* Merges default list parameters with an existing parameter object.
*
* @param {ListRequestParams} params
* @returns {object}
*/
export const withDefaultListParams = (params: ListRequestParams) => ({
count: 20,
retry_type: 'no_retry',
...params,
});