Download wp-calypso/client/lib/get-google-media/index.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/get-google-media/index.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/lib/get-google-media/index.ts
-
curl -L -o index.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/get-google-media/index.ts
1.08 kB
| import wpcom from 'calypso/lib/wp'; | |
| export function getGoogleMediaViaProxy( mediaUrl: string ): Promise< Blob > { | |
| const params = { | |
| path: '/meta/external-media/proxy/google_photos', | |
| apiNamespace: 'wpcom/v2', | |
| body: { | |
| url: mediaUrl, | |
| }, | |
| }; | |
| return new Promise( ( resolve, reject ) => { | |
| return wpcom.req.post( | |
| { ...params, responseType: 'blob' }, | |
| ( error: Error | null, data: Blob ) => { | |
| if ( error || ! ( data instanceof globalThis.Blob ) ) { | |
| reject( error ); | |
| } else { | |
| resolve( data ); | |
| } | |
| } | |
| ); | |
| } ); | |
| } | |
| export function getGoogleMediaViaProxyRetry( mediaUrl: string ): Promise< Blob | unknown > { | |
| let retries = 0; | |
| const request = () => | |
| getGoogleMediaViaProxy( mediaUrl ).catch( ( error: Error ) => { | |
| // Retry three times with exponential backoff times | |
| if ( retries < 3 ) { | |
| return new Promise( ( resolve ) => { | |
| ++retries; | |
| setTimeout( | |
| () => { | |
| resolve( request() ); | |
| }, | |
| ( retries * retries * 1000 ) / 2 | |
| ); | |
| } ); | |
| } | |
| return Promise.reject( error ); | |
| } ); | |
| return request(); | |
| } | |