|
@@ -1352,182 +1352,6 @@
|
|
|
return path;
|
|
|
}
|
|
|
|
|
|
-+ (void)extractImageVideoFromAssetLocalIdentifierForUpload:(tableMetadata *)metadataForUpload queue:(dispatch_queue_t)queue completion:(void(^)(tableMetadata *metadata, NSString* fileNamePath))completion
|
|
|
-{
|
|
|
- if (metadataForUpload == nil) {
|
|
|
- dispatch_async(queue, ^{
|
|
|
- completion(nil, nil);
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- tableMetadata *metadata = [[NCManageDatabase shared] copyObjectWithMetadata:metadataForUpload];
|
|
|
-
|
|
|
- PHFetchResult *result = [PHAsset fetchAssetsWithLocalIdentifiers:@[metadata.assetLocalIdentifier] options:nil];
|
|
|
- if (!result.count) {
|
|
|
- dispatch_async(queue, ^{
|
|
|
- completion(nil, nil);
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- PHAsset *asset = result[0];
|
|
|
- NSDate *creationDate = asset.creationDate;
|
|
|
- NSDate *modificationDate = asset.modificationDate;
|
|
|
-
|
|
|
- // IMAGE
|
|
|
- if (asset.mediaType == PHAssetMediaTypeImage) {
|
|
|
-
|
|
|
- PHImageRequestOptions *options = [PHImageRequestOptions new];
|
|
|
- options.networkAccessAllowed = YES;
|
|
|
- options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
|
|
|
- options.synchronous = YES;
|
|
|
- options.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
|
|
|
-
|
|
|
- NSLog(@"cacheAsset: %f", progress);
|
|
|
-
|
|
|
- if (error) {
|
|
|
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:NCGlobal.shared.notificationCenterUploadedFile object:nil userInfo:@{@"ocId": metadata.ocId, @"errorCode": @(error.code), @"errorDescription": [NSString stringWithFormat:@"Image request iCloud failed [%@]", error.description]}];
|
|
|
- dispatch_async(queue, ^{
|
|
|
- completion(nil, nil);
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- NSString *extensionAsset = [[[asset valueForKey:@"filename"] pathExtension] uppercaseString];
|
|
|
-
|
|
|
- //raw image will always ignore any edits made to the photo if compatibility is false
|
|
|
- if ([extensionAsset isEqualToString:@"DNG"]) {
|
|
|
- options.version = PHImageRequestOptionsVersionOriginal;
|
|
|
- }
|
|
|
-
|
|
|
- [[PHImageManager defaultManager] requestImageDataForAsset:asset options:options resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
|
|
|
-
|
|
|
- NSError *error = nil;
|
|
|
- NSString *fileName = metadata.fileNameView;
|
|
|
-
|
|
|
- if (([extensionAsset isEqualToString:@"HEIC"] || [extensionAsset isEqualToString:@"DNG"]) && [CCUtility getFormatCompatibility]) {
|
|
|
-
|
|
|
- CIImage *ciImage = [CIImage imageWithData:imageData];
|
|
|
- CIContext *context = [CIContext context];
|
|
|
- imageData = [context JPEGRepresentationOfImage:ciImage colorSpace:ciImage.colorSpace options:@{}];
|
|
|
-
|
|
|
- NSString *fileNameJPEG = [[metadata.fileName lastPathComponent] stringByDeletingPathExtension];
|
|
|
- fileName = [fileNameJPEG stringByAppendingString:@".jpg"];
|
|
|
- metadata.contentType = @"image/jpeg";
|
|
|
- metadata.ext = @"jpg";
|
|
|
- }
|
|
|
-
|
|
|
- NSString *fileNamePath = [NSTemporaryDirectory() stringByAppendingString:fileName];
|
|
|
-
|
|
|
- [[NSFileManager defaultManager]removeItemAtPath:fileNamePath error:nil];
|
|
|
- [imageData writeToFile:fileNamePath options:NSDataWritingAtomic error:&error];
|
|
|
-
|
|
|
- if (metadata.e2eEncrypted) {
|
|
|
- metadata.fileNameView = fileName;
|
|
|
- } else {
|
|
|
- metadata.fileNameView = fileName;
|
|
|
- metadata.fileName = fileName;
|
|
|
- }
|
|
|
-
|
|
|
- metadata.creationDate = creationDate;
|
|
|
- metadata.date = modificationDate;
|
|
|
- metadata.size = [[NCUtilityFileSystem shared] getFileSizeWithFilePath:fileNamePath];
|
|
|
-
|
|
|
- dispatch_async(queue, ^{
|
|
|
- completion(metadata, fileNamePath);
|
|
|
- });
|
|
|
- }];
|
|
|
- }
|
|
|
-
|
|
|
- // VIDEO
|
|
|
- if (asset.mediaType == PHAssetMediaTypeVideo) {
|
|
|
-
|
|
|
- PHVideoRequestOptions *options = [PHVideoRequestOptions new];
|
|
|
- options.networkAccessAllowed = YES;
|
|
|
- options.version = PHVideoRequestOptionsVersionOriginal;
|
|
|
- options.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
|
|
|
-
|
|
|
- NSLog(@"cacheAsset: %f", progress);
|
|
|
-
|
|
|
- if (error) {
|
|
|
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:NCGlobal.shared.notificationCenterUploadedFile object:nil userInfo:@{@"ocId": metadata.ocId, @"errorCode": @(error.code), @"errorDescription": [NSString stringWithFormat:@"Video request iCloud failed [%@]", error.description]}];
|
|
|
- dispatch_async(queue, ^{
|
|
|
- completion(nil, nil);
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- [[PHImageManager defaultManager] requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
|
|
|
-
|
|
|
- if ([asset isKindOfClass:[AVURLAsset class]]) {
|
|
|
-
|
|
|
- NSString *fileNamePath = [NSTemporaryDirectory() stringByAppendingString:metadata.fileNameView];
|
|
|
- NSURL *fileNamePathURL = [[NSURL alloc] initFileURLWithPath:fileNamePath];
|
|
|
- NSError *error = nil;
|
|
|
-
|
|
|
- [[NSFileManager defaultManager] removeItemAtURL:fileNamePathURL error:nil];
|
|
|
- [[NSFileManager defaultManager] copyItemAtURL:[(AVURLAsset *)asset URL] toURL:fileNamePathURL error:&error];
|
|
|
-
|
|
|
- dispatch_async(queue, ^{
|
|
|
- if (error) {
|
|
|
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:NCGlobal.shared.notificationCenterUploadedFile object:nil userInfo:@{@"ocId": metadata.ocId, @"errorCode": @(error.code), @"errorDescription": [NSString stringWithFormat:@"Video request iCloud failed [%@]", error.description]}];
|
|
|
- completion(nil, nil);
|
|
|
- } else {
|
|
|
- metadata.creationDate = creationDate;
|
|
|
- metadata.date = modificationDate;
|
|
|
- metadata.size = [[NCUtilityFileSystem shared] getFileSizeWithFilePath:fileNamePath];
|
|
|
- completion(metadata, fileNamePath);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }];
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-+ (void)extractLivePhotoAsset:(PHAsset*)asset filePath:(NSString *)filePath queue:(dispatch_queue_t)queue withCompletion:(void (^)(NSURL* url))completion
|
|
|
-{
|
|
|
- [CCUtility removeFileAtPath:filePath];
|
|
|
- NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
|
|
|
- PHLivePhotoRequestOptions *options = [PHLivePhotoRequestOptions new];
|
|
|
- options.deliveryMode = PHImageRequestOptionsDeliveryModeFastFormat;
|
|
|
- options.networkAccessAllowed = YES;
|
|
|
-
|
|
|
- [[PHImageManager defaultManager] requestLivePhotoForAsset:asset targetSize:[UIScreen mainScreen].bounds.size contentMode:PHImageContentModeDefault options:options resultHandler:^(PHLivePhoto * _Nullable livePhoto, NSDictionary * _Nullable info) {
|
|
|
- if (livePhoto) {
|
|
|
- NSArray *assetResources = [PHAssetResource assetResourcesForLivePhoto:livePhoto];
|
|
|
- PHAssetResource *videoResource = nil;
|
|
|
- for(PHAssetResource *resource in assetResources){
|
|
|
- if (resource.type == PHAssetResourceTypePairedVideo) {
|
|
|
- videoResource = resource;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if(videoResource){
|
|
|
- [[PHAssetResourceManager defaultManager] writeDataForAssetResource:videoResource toFile:fileUrl options:nil completionHandler:^(NSError * _Nullable error) {
|
|
|
- dispatch_async(queue, ^{
|
|
|
- if (!error) {
|
|
|
- completion(fileUrl);
|
|
|
- } else {
|
|
|
- completion(nil);
|
|
|
- }
|
|
|
- });
|
|
|
- }];
|
|
|
- } else {
|
|
|
- dispatch_async(queue, ^{
|
|
|
- completion(nil);
|
|
|
- });
|
|
|
- }
|
|
|
- } else {
|
|
|
- dispatch_async(queue, ^{
|
|
|
- completion(nil);
|
|
|
- });
|
|
|
- }
|
|
|
- }];
|
|
|
-}
|
|
|
-
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
|
#pragma mark ===== E2E Encrypted =====
|
|
|
#pragma --------------------------------------------------------------------------------------------
|