This repository was archived by the owner on Feb 18, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 329
Expand file tree
/
Copy pathexplorerXhr.ts
More file actions
51 lines (47 loc) · 1.33 KB
/
explorerXhr.ts
File metadata and controls
51 lines (47 loc) · 1.33 KB
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
import { SESSION_ID_KEY, fetchJSON } from '../../../http'
import { OpeningData, TablebaseData } from './interfaces'
const explorerEndpoint = 'https://explorer.lichess.ovh'
const tablebaseEndpoint = 'https://tablebase.lichess.ovh'
export interface OpeningConf {
db: string
speeds?: string[]
ratings?: number[]
}
export function openingXhr(variant: VariantKey, fen: string, config: OpeningConf, withGames: boolean): Promise<OpeningData> {
const query: any = {
fen,
variant,
source: 'mobile'
}
if (!withGames) {
query.topGames = 0
query.recentGames = 0
}
if (config.db === 'lichess') {
if (config.speeds) query.speeds = config.speeds.join(',')
if (config.ratings) query.ratings = config.ratings.join(',')
}
return fetchJSON(explorerEndpoint + '/' + config.db, {
headers: {
'Accept': 'application/json',
'X-Requested-With': '__delete',
[SESSION_ID_KEY]: '__delete',
},
credentials: 'omit',
query
})
}
export function tablebaseXhr(variant: VariantKey, fen: string, timeout?: number): Promise<TablebaseData> {
return fetchJSON(tablebaseEndpoint + '/' + variant, {
headers: {
'Accept': 'application/json, text/*',
'X-Requested-With': '__delete',
[SESSION_ID_KEY]: '__delete',
},
credentials: 'omit',
query: {
fen: fen
},
timeout
})
}