Browse Source

clear code

Marino Faggiana 7 years ago
parent
commit
fa6572ef3c

+ 4 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -231,6 +231,8 @@
 		F75EDFBD1E8C112F00E6F369 /* libsqlite3.0.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = F75EDFBC1E8C112F00E6F369 /* libsqlite3.0.tbd */; };
 		F75EDFBF1E8C116D00E6F369 /* libstdc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = F75EDFBE1E8C116D00E6F369 /* libstdc++.tbd */; };
 		F761831F1F03B6C300D8D483 /* NCRequestAsset.m in Sources */ = {isa = PBXBuildFile; fileRef = F761831E1F03B6C300D8D483 /* NCRequestAsset.m */; };
+		F76183221F03B7BE00D8D483 /* NCRequestAsset.m in Sources */ = {isa = PBXBuildFile; fileRef = F761831E1F03B6C300D8D483 /* NCRequestAsset.m */; };
+		F761832B1F03B7BE00D8D483 /* NCRequestAsset.m in Sources */ = {isa = PBXBuildFile; fileRef = F761831E1F03B6C300D8D483 /* NCRequestAsset.m */; };
 		F762CAF61EACB66200B38484 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = F762CAA01EACB66200B38484 /* Info.plist */; };
 		F762CAF71EACB66200B38484 /* XLFormBaseCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F762CAA41EACB66200B38484 /* XLFormBaseCell.m */; };
 		F762CAF81EACB66200B38484 /* XLFormButtonCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F762CAA61EACB66200B38484 /* XLFormButtonCell.m */; };
@@ -4260,6 +4262,7 @@
 				F71459F11D12E3B700CAFEEC /* CCMove.m in Sources */,
 				F70022C31EC4C9100080073F /* OCNotifications.m in Sources */,
 				F71459F31D12E3B700CAFEEC /* UIImage+Resizing.m in Sources */,
+				F76183221F03B7BE00D8D483 /* NCRequestAsset.m in Sources */,
 				F71459F71D12E3B700CAFEEC /* CCGraphics.m in Sources */,
 				F7BAADC91ED5A87C00B7EAD4 /* NCDatabase.swift in Sources */,
 				F70022BD1EC4C9100080073F /* OCExternalSites.m in Sources */,
@@ -4352,6 +4355,7 @@
 				F70022D91EC4C9100080073F /* NSDate+RFC1123.m in Sources */,
 				F73CC06E1E813DFF006E3047 /* BKPasscodeField.m in Sources */,
 				F74344841E127F84001CC831 /* RNCryptorEngine.m in Sources */,
+				F761832B1F03B7BE00D8D483 /* NCRequestAsset.m in Sources */,
 				F74344851E127F86001CC831 /* RNDecryptor.m in Sources */,
 				F74344881E127F9C001CC831 /* UIImage+animatedGIF.m in Sources */,
 				F73CC0771E813DFF006E3047 /* BKPasscodeViewController.m in Sources */,

+ 0 - 46
iOSClient/Utility/NCRequestAsset.h

@@ -1,46 +0,0 @@
-//
-//  NCRequestAsset.h
-//  Nextcloud
-//
-//  Created by Marino Faggiana on 16/06/17.
-//  Copyright © 2017 TWS. All rights reserved.
-//
-//  Author Marino Faggiana <m.faggiana@twsweb.it>
-//
-//  This program is free software: you can redistribute it and/or modify
-//  it under the terms of the GNU General Public License as published by
-//  the Free Software Foundation, either version 3 of the License, or
-//  (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#import <Foundation/Foundation.h>
-#import <Photos/Photos.h>
-#import "CCNetworking.h"
-
-@protocol NCRequestAssetDelegate;
-
-@interface NCRequestAsset : NSObject
-
-@property (nonatomic, weak) id <NCRequestAssetDelegate> delegate;
-
-@property (nonatomic, strong) AVAssetExportSession *exportSession;
-
-- (void)writeAssetToSandboxFileName:(NSString *)fileName assetLocalIdentifier:(NSString *)assetLocalIdentifier selector:(NSString *)selector selectorPost:(NSString *)selectorPost errorCode:(NSInteger)errorCode metadataNet:(CCMetadataNet *)metadataNet serverUrl:(NSString *)serverUrl activeUrl:(NSString *)activeUrl directoryUser:(NSString *)directoryUser cryptated:(BOOL)cryptated session:(NSString *)session taskStatus:(NSInteger)taskStatus delegate:(id)delegate;
-
-@end
-
-@protocol NCRequestAssetDelegate <NSObject>
-
-@optional - (void)addDatabaseAutoUpload:(CCMetadataNet *)metadataNet asset:(PHAsset *)asset;
-
-@optional - (void)upload:(NSString *)fileName serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated template:(BOOL)template onlyPlist:(BOOL)onlyPlist fileNameTemplate:(NSString *)fileNameTemplate assetLocalIdentifier:(NSString *)assetLocalIdentifier session:(NSString *)session taskStatus:(NSInteger)taskStatus selector:(NSString *)selector selectorPost:(NSString *)selectorPost errorCode:(NSInteger)errorCode delegate:(id)delegate;
-
-@end

+ 0 - 171
iOSClient/Utility/NCRequestAsset.m

@@ -1,171 +0,0 @@
-//
-//  NCRequestAsset.m
-//  Nextcloud
-//
-//  Created by Marino Faggiana on 16/06/17.
-//  Copyright © 2017 TWS. All rights reserved.
-//
-
-#import "NCRequestAsset.h"
-#import "AppDelegate.h"
-
-#import "NCBridgeSwift.h"
-
-@implementation NCRequestAsset
-
-- (void)writeAssetToSandboxFileName:(NSString *)fileName assetLocalIdentifier:(NSString *)assetLocalIdentifier selector:(NSString *)selector selectorPost:(NSString *)selectorPost errorCode:(NSInteger)errorCode metadataNet:(CCMetadataNet *)metadataNet serverUrl:(NSString *)serverUrl activeUrl:(NSString *)activeUrl directoryUser:(NSString *)directoryUser cryptated:(BOOL)cryptated session:(NSString *)session taskStatus:(NSInteger)taskStatus delegate:(id)delegate
-{
-    PHFetchResult *result = [PHAsset fetchAssetsWithLocalIdentifiers:@[assetLocalIdentifier] options:nil];
-    
-    if (!result.count) {
-        
-        [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:@"Internal error image/video not found" type:k_activityTypeFailure verbose:k_activityVerboseHigh activeUrl:activeUrl];
-        
-        dispatch_async(dispatch_get_main_queue(), ^{
-            if (delegate)
-                if ([delegate respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
-                    [delegate uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:@"Internal error image/video not found" errorCode: k_CCErrorInternalError];
-        });
-        
-        return;
-    }
-
-    PHAsset *asset = result[0];
-    PHAssetMediaType assetMediaType = asset.mediaType;
-    __block NSError *error = nil;
-    
-    // VIDEO
-    if (assetMediaType == PHAssetMediaTypeVideo) {
-
-        @autoreleasepool {
-            
-            dispatch_semaphore_t semaphoreGroup = dispatch_semaphore_create(0);
-
-            PHVideoRequestOptions *options = [PHVideoRequestOptions new];
-            options.networkAccessAllowed = YES; // iCloud
-            
-            [[PHImageManager defaultManager] requestPlayerItemForVideo:asset options:options resultHandler:^(AVPlayerItem * _Nullable playerItem, NSDictionary * _Nullable info) {
-                
-                if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileName]])
-                    [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileName] error:nil];
-                
-                _exportSession = [[AVAssetExportSession alloc] initWithAsset:playerItem.asset presetName:AVAssetExportPresetHighestQuality];
-                
-                if (_exportSession) {
-                    
-                    _exportSession.outputURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileName]];
-                    _exportSession.outputFileType = AVFileTypeQuickTimeMovie;
-                    
-                    [_exportSession exportAsynchronouslyWithCompletionHandler:^{
-                        
-                        dispatch_semaphore_signal(semaphoreGroup);
-                        
-                        if (AVAssetExportSessionStatusCompleted == _exportSession.status) {
-                            
-                            //OK selectorUploadAutoUpload
-                            if ([selector isEqualToString:selectorUploadAutoUpload]) {
-                                if ([self.delegate respondsToSelector:@selector(addDatabaseAutoUpload:asset:)])
-                                    [self.delegate addDatabaseAutoUpload:metadataNet asset:asset];
-                            } else {
-                                if ([self.delegate respondsToSelector:@selector(upload:serverUrl:cryptated:template:onlyPlist:fileNameTemplate:assetLocalIdentifier:session:taskStatus:selector:selectorPost:errorCode:delegate:)])
-                                    [self.delegate upload:fileName serverUrl:serverUrl cryptated:cryptated template:NO onlyPlist:NO fileNameTemplate:nil assetLocalIdentifier:assetLocalIdentifier session:session taskStatus:taskStatus selector:selector selectorPost:selectorPost errorCode:errorCode delegate:delegate];
-                            }
-                            
-                        } else if (AVAssetExportSessionStatusFailed == _exportSession.status) {
-                            
-                            // Delete record on Table Auto Upload
-                            if ([selector isEqualToString:selectorUploadAutoUpload] || [selector isEqualToString:selectorUploadAutoUploadAll])
-                                [[NCManageDatabase sharedInstance] deleteAutoUploadWithAssetLocalIdentifier:assetLocalIdentifier];
-                            
-                            // Activity
-                            [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:[NSString stringWithFormat:@"%@ [%@]",NSLocalizedString(@"_read_file_error_", nil), error.description] type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:activeUrl];
-                            
-                            // Error for uploadFileFailure
-                            dispatch_async(dispatch_get_main_queue(), ^{
-                                if (delegate)
-                                    if ([delegate respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
-                                        [delegate uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:@"_read_file_error_" errorCode:[NSError errorWithDomain:@"it.twsweb.cryptocloud" code:kCFURLErrorFileDoesNotExist userInfo:nil].code];
-                            });
-                            
-                        } else {
-                            NSLog(@"Export Session Status: %ld", (long)_exportSession.status);
-                        }
-                    }];
-                    
-                } else {
-                    
-                    dispatch_semaphore_signal(semaphoreGroup);
-                    
-                    // Delete record on Table Auto Upload
-                    if ([selector isEqualToString:selectorUploadAutoUpload] || [selector isEqualToString:selectorUploadAutoUploadAll])
-                        [[NCManageDatabase sharedInstance] deleteAutoUploadWithAssetLocalIdentifier:assetLocalIdentifier];
-                    
-                    // Activity
-                    [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:[NSString stringWithFormat:@"%@ [%@]",NSLocalizedString(@"_read_file_error_", nil), error.description] type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:activeUrl];
-                    
-                    // Error for uploadFileFailure
-                    dispatch_async(dispatch_get_main_queue(), ^{
-                        if (delegate)
-                            if ([delegate respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
-                                [delegate uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:@"_read_file_error_" errorCode:[NSError errorWithDomain:@"it.twsweb.cryptocloud" code:kCFURLErrorFileDoesNotExist userInfo:nil].code];
-                    });
-                }
-            }];
-            
-            while (dispatch_semaphore_wait(semaphoreGroup, DISPATCH_TIME_NOW))
-                [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
-        }
-    }
-    
-    // IMAGE
-    if (assetMediaType == PHAssetMediaTypeImage) {
-        
-        @autoreleasepool {
-            
-            dispatch_semaphore_t semaphoreGroup = dispatch_semaphore_create(0);
-            
-            PHImageRequestOptions *options = [PHImageRequestOptions new];
-            options.networkAccessAllowed = YES; // iCloud
-            
-            [[PHImageManager defaultManager] requestImageDataForAsset:asset options:options resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
-                
-                [imageData writeToFile:[NSString stringWithFormat:@"%@/%@", directoryUser, fileName] options:NSDataWritingAtomic error:&error];
-                
-                if (error) {
-                    
-                    // Delete record on Table Auto Upload
-                    if ([selector isEqualToString:selectorUploadAutoUpload] || [selector isEqualToString:selectorUploadAutoUploadAll])
-                        [[NCManageDatabase sharedInstance] deleteAutoUploadWithAssetLocalIdentifier:assetLocalIdentifier];
-                    
-                    // Activity
-                    [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:[NSString stringWithFormat:@"%@ [%@]",NSLocalizedString(@"_read_file_error_", nil), error.description] type:k_activityTypeFailure verbose:k_activityVerboseDefault  activeUrl:activeUrl];
-                    
-                    // Error for uploadFileFailure
-                    dispatch_async(dispatch_get_main_queue(), ^{
-                        if (delegate)
-                            if ([delegate respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
-                                [delegate uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:@"_read_file_error_" errorCode:[NSError errorWithDomain:@"it.twsweb.cryptocloud" code:kCFURLErrorFileDoesNotExist userInfo:nil].code];
-                    });
-                    
-                } else {
-                    
-                    //OK selectorUploadAutoUpload
-                    if ([selector isEqualToString:selectorUploadAutoUpload]) {
-                        if ([self.delegate respondsToSelector:@selector(addDatabaseAutoUpload:asset:)])
-                            [self.delegate addDatabaseAutoUpload:metadataNet asset:asset];
-                    } else {
-                        if ([self.delegate respondsToSelector:@selector(upload:serverUrl:cryptated:template:onlyPlist:fileNameTemplate:assetLocalIdentifier:session:taskStatus:selector:selectorPost:errorCode:delegate:)])
-                            [self.delegate upload:fileName serverUrl:serverUrl cryptated:cryptated template:NO onlyPlist:NO fileNameTemplate:nil assetLocalIdentifier:assetLocalIdentifier session:session taskStatus:taskStatus selector:selector selectorPost:selectorPost errorCode:errorCode delegate:delegate];
-                    }
-                }
-                
-                dispatch_semaphore_signal(semaphoreGroup);
-            }];
-            
-            while (dispatch_semaphore_wait(semaphoreGroup, DISPATCH_TIME_NOW))
-                [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
-        }
-    }
-}
-
-@end