diff --git a/native/backup/api.js b/native/backup/api.js --- a/native/backup/api.js +++ b/native/backup/api.js @@ -99,4 +99,30 @@ return getBackupBytesFromBlob(blob); } -export { uploadBackup, getBackupID, getUserKeys }; +async function getUserData( + backupID: string, + auth: BackupAuth, +): Promise { + const authHeader = getBackupAuthorizationHeader(auth); + + const getUserDataEndpoint = backupService.httpEndpoints.GET_USER_DATA; + const getUserDataResponse = await fetch( + makeBackupServiceEndpointURL(getUserDataEndpoint, { backupID }), + { + method: getUserDataEndpoint.method, + headers: { + Authorization: authHeader, + }, + }, + ); + + if (!getUserDataResponse.ok) { + const { status, statusText } = getUserDataResponse; + throw new Error(`Server responded with HTTP ${status}: ${statusText}`); + } + + const blob = await getUserDataResponse.blob(); + return getBackupBytesFromBlob(blob); +} + +export { uploadBackup, getBackupID, getUserKeys, getUserData };