0

Show status of an async locale download

by
Published Oct 17, 2025

Show status of already started async locale download. If the download is finished, the download link will be returned.

Script phrase Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Phrase = {
3
	token: string
4
	baseUrl: string
5
}
6
/**
7
 * Show status of an async locale download
8
 * Show status of already started async locale download. If the download is finished, the download link will be returned.
9
 */
10
export async function main(
11
	auth: Phrase,
12
	project_id: string,
13
	locale_id: string,
14
	id: string,
15
	If_Modified_Since: string,
16
	If_None_Match: string
17
) {
18
	const url = new URL(`${auth.baseUrl}/projects/${project_id}/locales/${locale_id}/downloads/${id}`)
19

20
	const response = await fetch(url, {
21
		method: 'GET',
22
		headers: {
23
			'If-Modified-Since': If_Modified_Since,
24
			'If-None-Match': If_None_Match,
25
			Authorization: 'ApiToken ' + auth.token
26
		},
27
		body: undefined
28
	})
29
	if (!response.ok) {
30
		const text = await response.text()
31
		throw new Error(`${response.status} ${text}`)
32
	}
33
	return await response.json()
34
}
35