Edits history of script submission #17933 for ' Show status of an async locale download (phrase)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Phrase = {
    	token: string
    	baseUrl: string
    }
    /**
     * Show status of an async locale download
     * Show status of already started async locale download. If the download is finished, the download link will be returned.
     */
    export async function main(
    	auth: Phrase,
    	project_id: string,
    	locale_id: string,
    	id: string,
    	If_Modified_Since: string,
    	If_None_Match: string
    ) {
    	const url = new URL(`${auth.baseUrl}/projects/${project_id}/locales/${locale_id}/downloads/${id}`)
    
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			'If-Modified-Since': If_Modified_Since,
    			'If-None-Match': If_None_Match,
    			Authorization: 'ApiToken ' + auth.token
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 235 days ago