forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrowdin.ts
More file actions
57 lines (48 loc) · 1.74 KB
/
crowdin.ts
File metadata and controls
57 lines (48 loc) · 1.74 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
52
53
54
55
56
57
/**
* 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 { fetchGet } from './http'
/**
* 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 = await fetchGet(url, { headers: { "Authorization": auth } })
const data: { data: { data: TranslationStatusInfo }[] } = await response.json()
return data.data.map(i => i.data)
}
export async function getMembers(): Promise<MemberInfo[]> {
const result: MemberInfo[] = []
const auth = `Bearer ${PUBLIC_TOKEN}`
const limit = 10
let offset = 0
while (true) {
const url = `https://api.crowdin.com/api/v2/projects/${CROWDIN_PROJECT_ID}/members?limit=${limit}&offset=${offset}`
const response = await fetchGet(url, { headers: { "Authorization": auth } })
const data: { data: { data: MemberInfo }[] } = await response.json()
const newItems = data?.data?.map(i => i.data) ?? []
result.push(...newItems)
if (newItems.length < limit) break
offset += limit
}
return result
}