-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathcrowdin.ts
More file actions
50 lines (44 loc) · 1.54 KB
/
crowdin.ts
File metadata and controls
50 lines (44 loc) · 1.54 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
/**
* Copyright (c) 2022-present Hengyang Zhang
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
import { CROWDIN_PROJECT_ID } from "@util/constant/url"
import axios, { type AxiosResponse } from "axios"
/**
* Used to obtain translation status
*/
const PUBLIC_TOKEN = '5e0d53accb6e8c490a1af2914c0963f78082221d7bc1dcb0d56b8e3856a875e432a2e353a948688e'
export type TranslationStatusInfo = {
/**
* https://developer.crowdin.com/language-codes/
*/
languageId: string
translationProgress: number
}
export type MemberInfo = {
username: string
joinedAt: string
avatarUrl: string
}
export async function getTranslationStatus(): Promise<TranslationStatusInfo[]> {
const limit = 500
const auth = `Bearer ${PUBLIC_TOKEN}`
const url = `https://api.crowdin.com/api/v2/projects/${CROWDIN_PROJECT_ID}/languages/progress?limit=${limit}`
const response: AxiosResponse = await axios.get(url, {
headers: { "Authorization": auth }
})
const data: { data: { data: TranslationStatusInfo }[] } = response.data
return data.data.map(i => i.data)
}
export async function getMembers(): Promise<MemberInfo[]> {
const limit = 20
const auth = `Bearer ${PUBLIC_TOKEN}`
const url = `https://api.crowdin.com/api/v2/projects/${CROWDIN_PROJECT_ID}/members?limit=${limit}`
const response: AxiosResponse = await axios.get(url, {
headers: { "Authorization": auth }
})
const data: { data: { data: MemberInfo }[] } = response.data
return data.data.map(i => i.data)
}