Page MenuHomePhabricator

D8995.id30474.diff
No OneTemporary

D8995.id30474.diff

diff --git a/native/backup/api.js b/native/backup/api.js
--- a/native/backup/api.js
+++ b/native/backup/api.js
@@ -7,6 +7,7 @@
import { makeBackupServiceEndpointURL } from 'lib/utils/backup-service.js';
import { toBase64URL } from 'lib/utils/base64.js';
+import { getBackupBytesFromBlob } from './conversion-utils.js';
import { commUtilsModule } from '../native-modules.js';
import { arrayBufferFromBlob } from '../utils/blob-utils-module.js';
@@ -76,4 +77,30 @@
return backupID;
}
-export { uploadBackup, getBackupID };
+async function getUserKeysAuth(
+ backupID: string,
+ auth: BackupAuth,
+): Promise<Uint8Array> {
+ const authHeader = getBackupAuthorizationHeader(auth);
+
+ const getUserKeysEndpoint = backupService.httpEndpoints.GET_USER_KEYS_AUTH;
+ const getUserKeysResponse = await fetch(
+ makeBackupServiceEndpointURL(getUserKeysEndpoint, { backup_id: backupID }),
+ {
+ method: getUserKeysEndpoint.method,
+ headers: {
+ Authorization: authHeader,
+ },
+ },
+ );
+
+ if (!getUserKeysResponse.ok) {
+ const { status, statusText } = getUserKeysResponse;
+ throw new Error(`Server responded with HTTP ${status}: ${statusText}`);
+ }
+
+ const blob = await getUserKeysResponse.blob();
+ return getBackupBytesFromBlob(blob);
+}
+
+export { uploadBackup, getBackupID, getUserKeysAuth };
diff --git a/native/backup/conversion-utils.js b/native/backup/conversion-utils.js
new file mode 100644
--- /dev/null
+++ b/native/backup/conversion-utils.js
@@ -0,0 +1,13 @@
+// @flow
+
+import { commUtilsModule } from '../native-modules.js';
+import { arrayBufferFromBlob } from '../utils/blob-utils-module.js';
+
+function getBackupBytesFromBlob(blob: Blob): Uint8Array {
+ const buffer = arrayBufferFromBlob(blob);
+ const str = commUtilsModule.decodeUTF8ArrayBufferToString(buffer);
+ const decodedBuffer = commUtilsModule.base64DecodeBuffer(str);
+ return new Uint8Array(decodedBuffer);
+}
+
+export { getBackupBytesFromBlob };

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 4:10 PM (18 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2571499
Default Alt Text
D8995.id30474.diff (1 KB)

Event Timeline