mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-05-01 14:13:22 +01:00
Add upload support for the main backup file in backupV2.
This commit is contained in:
committed by
Clark Chen
parent
f93a9a0f22
commit
f4bcfca323
@@ -16,6 +16,7 @@ import org.whispersystems.signalservice.api.NetworkResult
|
||||
import org.whispersystems.signalservice.api.backup.BackupKey
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI
|
||||
import org.whispersystems.signalservice.internal.push.PushServiceSocket
|
||||
import java.io.InputStream
|
||||
|
||||
/**
|
||||
* Class to interact with various archive-related endpoints.
|
||||
@@ -101,6 +102,24 @@ class ArchiveApi(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a resumable upload URL you can use to upload your main message backup file to cloud storage.
|
||||
*/
|
||||
fun getBackupResumableUploadUrl(archiveFormResponse: ArchiveMessageBackupUploadFormResponse): NetworkResult<String> {
|
||||
return NetworkResult.fromFetch {
|
||||
pushServiceSocket.getResumableUploadUrl(archiveFormResponse)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploads your main backup file to cloud storage.
|
||||
*/
|
||||
fun uploadBackupFile(archiveFormResponse: ArchiveMessageBackupUploadFormResponse, resumableUploadUrl: String, data: InputStream, dataLength: Long): NetworkResult<Unit> {
|
||||
return NetworkResult.fromFetch {
|
||||
pushServiceSocket.uploadBackupFile(archiveFormResponse, resumableUploadUrl, data, dataLength)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getZkCredential(backupKey: BackupKey, serviceCredential: ArchiveServiceCredential): BackupAuthCredential {
|
||||
val backupAuthResponse = BackupAuthCredentialResponse(serviceCredential.credential)
|
||||
val backupRequestContext = BackupAuthCredentialRequestContext.create(backupKey.value, aci.rawUuid)
|
||||
|
||||
@@ -1637,6 +1637,10 @@ public class PushServiceSocket {
|
||||
}
|
||||
}
|
||||
|
||||
public String getResumableUploadUrl(ArchiveMessageBackupUploadFormResponse uploadFormResponse) throws IOException {
|
||||
return getResumableUploadUrl(uploadFormResponse.getCdn(), uploadFormResponse.getSignedUploadLocation(), uploadFormResponse.getHeaders());
|
||||
}
|
||||
|
||||
private String getResumableUploadUrl(int cdn, String signedUrl, Map<String, String> headers) throws IOException {
|
||||
ConnectionHolder connectionHolder = getRandom(cdnClientsMap.get(cdn), random);
|
||||
OkHttpClient okHttpClient = connectionHolder.getClient()
|
||||
@@ -1739,6 +1743,10 @@ public class PushServiceSocket {
|
||||
}
|
||||
}
|
||||
|
||||
public void uploadBackupFile(ArchiveMessageBackupUploadFormResponse uploadFormResponse, String resumableUploadUrl, InputStream data, long dataLength) throws IOException {
|
||||
uploadToCdn3(resumableUploadUrl, data, "application/octet-stream", dataLength, false, new NoCipherOutputStreamFactory(), null, null, uploadFormResponse.getHeaders());
|
||||
}
|
||||
|
||||
private AttachmentDigest uploadToCdn3(String resumableUrl,
|
||||
InputStream data,
|
||||
String contentType,
|
||||
|
||||
Reference in New Issue
Block a user