Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3348831
D8995.id30474.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D8995.id30474.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D8995: [client-backup] implement API call to get UserKeys
Attached
Detach File
Event Timeline
Log In to Comment