forked from Phoscur/oryx-macro-hax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oryx-downloader.ts
48 lines (41 loc) · 1.29 KB
/
oryx-downloader.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
import axios from 'axios'
import unzipper from 'unzipper'
const ORYX_GRAPHQL_URL = 'https://oryx.zsa.io/graphql'
export async function getKeymapSourceLink(hashId, revisionId = 'latest') {
const query = `
query getLayout($hashId: String!, $revisionId: String!, $geometry: String) {
Layout(hashId: $hashId, geometry: $geometry, revisionId: $revisionId) {
revision {
zipUrl
}
}
}`
const { data } = await axios.post(ORYX_GRAPHQL_URL, {
operationName: 'getLayout',
variables: {
hashId,
geometry: 'moonlander',
revisionId,
},
query,
})
return data.data.Layout.revision.zipUrl
}
export async function unzipKeymapSource(url, path) {
const response = await axios({
method: 'get',
url,
responseType: 'stream'
})
const unzip = unzipper.Extract({ path })
return response.data.pipe(unzip).promise()
}
export async function downloadKeymapSource(layoutHashId, path) {
const zipUrl = await getKeymapSourceLink(layoutHashId)
await unzipKeymapSource(zipUrl, path)
console.log('Downloaded layout', layoutHashId, 'from', zipUrl)
}
if (typeof require !== 'undefined' && require.main === module) {
const hashId = process.argv[2] || process.env.LAYOUT_ID || 'PqjlE'
downloadKeymapSource(hashId, process.env.LAYOUT_DIR || './layout_src')
}