|
|
@ -192,6 +192,10 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
|
|
|
|
pointer:attachment
|
|
|
|
pointer:attachment
|
|
|
|
success:markAndHandleSuccess
|
|
|
|
success:markAndHandleSuccess
|
|
|
|
failure:markAndHandleFailure];
|
|
|
|
failure:markAndHandleFailure];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (![OWSFileSystem deleteFile:encryptedDataFilePath]) {
|
|
|
|
|
|
|
|
OWSLogError(@"Could not delete temporary file.");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -295,9 +299,17 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
|
|
|
|
const long kMaxDownloadSize = 150 * 1024 * 1024;
|
|
|
|
const long kMaxDownloadSize = 150 * 1024 * 1024;
|
|
|
|
__block BOOL hasCheckedContentLength = NO;
|
|
|
|
__block BOOL hasCheckedContentLength = NO;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NSString *tempFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSUUID UUID].UUIDString];
|
|
|
|
|
|
|
|
NSURL *tempFileURL = [NSURL fileURLWithPath:tempFilePath];
|
|
|
|
|
|
|
|
|
|
|
|
__block NSURLSessionDownloadTask *task;
|
|
|
|
__block NSURLSessionDownloadTask *task;
|
|
|
|
void (^failureHandler)(NSError *) = ^(NSError *error) {
|
|
|
|
void (^failureHandler)(NSError *) = ^(NSError *error) {
|
|
|
|
OWSLogError(@"Failed to download attachment with error: %@", error.description);
|
|
|
|
OWSLogError(@"Failed to download attachment with error: %@", error.description);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (![OWSFileSystem deleteFileIfExists:tempFilePath]) {
|
|
|
|
|
|
|
|
OWSLogError(@"Could not delete temporary file.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
failureHandlerParam(task, error);
|
|
|
|
failureHandlerParam(task, error);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -308,13 +320,9 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
|
|
|
|
parameters:nil
|
|
|
|
parameters:nil
|
|
|
|
error:&serializationError];
|
|
|
|
error:&serializationError];
|
|
|
|
if (serializationError) {
|
|
|
|
if (serializationError) {
|
|
|
|
failureHandler(serializationError);
|
|
|
|
return failureHandler(serializationError);
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NSString *tempFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSUUID UUID].UUIDString];
|
|
|
|
|
|
|
|
NSURL *tempFileURL = [NSURL fileURLWithPath:tempFilePath];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
task = [manager downloadTaskWithRequest:request
|
|
|
|
task = [manager downloadTaskWithRequest:request
|
|
|
|
progress:^(NSProgress *progress) {
|
|
|
|
progress:^(NSProgress *progress) {
|
|
|
|
OWSAssertDebug(progress != nil);
|
|
|
|
OWSAssertDebug(progress != nil);
|
|
|
@ -403,6 +411,15 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
|
|
|
|
OWSErrorCodeInvalidMessage, NSLocalizedString(@"ERROR_MESSAGE_INVALID_MESSAGE", @""));
|
|
|
|
OWSErrorCodeInvalidMessage, NSLocalizedString(@"ERROR_MESSAGE_INVALID_MESSAGE", @""));
|
|
|
|
return failureHandler(error);
|
|
|
|
return failureHandler(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Protect the temporary file.
|
|
|
|
|
|
|
|
if (![OWSFileSystem ensureFileExists:filePath.path]) {
|
|
|
|
|
|
|
|
OWSLogError(@"Could not protect temporary file.");
|
|
|
|
|
|
|
|
NSError *error = OWSErrorWithCodeDescription(
|
|
|
|
|
|
|
|
OWSErrorCodeInvalidMessage, NSLocalizedString(@"ERROR_MESSAGE_INVALID_MESSAGE", @""));
|
|
|
|
|
|
|
|
return failureHandler(error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NSNumber *_Nullable fileSize = [OWSFileSystem fileSizeOfPath:filePath.path];
|
|
|
|
NSNumber *_Nullable fileSize = [OWSFileSystem fileSizeOfPath:filePath.path];
|
|
|
|
if (!fileSize) {
|
|
|
|
if (!fileSize) {
|
|
|
|
OWSLogError(@"Could not determine attachment file size.");
|
|
|
|
OWSLogError(@"Could not determine attachment file size.");
|
|
|
|