Parcourir la source

new design API thumbnail

Marino Faggiana il y a 6 ans
Parent
commit
bda3959614

+ 1 - 1
iOSClient/Networking/OCNetworking.h

@@ -50,7 +50,7 @@
 - (NSURLSessionTask *)uploadFileNameServerUrl:(NSString *)fileNameServerUrl fileNameLocalPath:(NSString *)fileNameLocalPath communication:(OCCommunication *)communication success:(void(^)(NSString *fileID, NSString *etag, NSDate *date))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
 
 - (void)downloadThumbnailWithMetadata:(tableMetadata*)metadata serverUrl:(NSString *)serverUrl withWidth:(CGFloat)width andHeight:(CGFloat)height completion:(void (^)(NSString *message, NSInteger errorCode))completion;
-
+- (void)downloadThumbnailWithPath:(NSString *)path file:(NSString *)file withWidth:(CGFloat)width andHeight:(CGFloat)height completion:(void (^)(NSString *message, NSInteger errorCode))completion;
 - (void)downloadPreviewWithMetadata:(tableMetadata*)metadata serverUrl:(NSString *)serverUrl withWidth:(CGFloat)width andHeight:(CGFloat)height completion:(void (^)(NSString *message, NSInteger errorCode))completion;
 
 - (void)readFolder:(NSString *)serverUrl depth:(NSString *)depth account:(NSString *)account success:(void(^)(NSArray *metadatas, tableMetadata *metadataFolder, NSString *directoryID))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;

+ 39 - 0
iOSClient/Networking/OCNetworking.m

@@ -402,6 +402,45 @@
     }
 }
 
+- (void)downloadThumbnailWithPath:(NSString *)path file:(NSString *)file withWidth:(CGFloat)width andHeight:(CGFloat)height completion:(void (^)(NSString *message, NSInteger errorCode))completion
+{    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:file]) {
+        
+        completion(nil, 0);
+        
+    } else {
+        
+        OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
+        
+        [communication setCredentialsWithUser:_activeUser andUserID:_activeUserID andPassword:_activePassword];
+        [communication setUserAgent:[CCUtility getUserAgent]];
+        
+        [communication getRemoteThumbnailByServer:_activeUrl ofFilePath:path withWidth:width andHeight:height onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSData *thumbnail, NSString *redirectedServer) {
+            
+            [thumbnail writeToFile:file atomically:YES];
+            
+            completion(nil, 0);
+            
+        } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
+            
+            NSString *message;
+            
+            NSInteger errorCode = response.statusCode;
+            if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
+                errorCode = error.code;
+            
+            // Error
+            if (errorCode == 503)
+                message = NSLocalizedString(@"_server_error_retry_", nil);
+            else
+                message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
+            
+            completion(message, errorCode);
+        }];
+    }
+}
+
+
 - (void)downloadPreviewWithMetadata:(tableMetadata*)metadata serverUrl:(NSString *)serverUrl withWidth:(CGFloat)width andHeight:(CGFloat)height completion:(void (^)(NSString *message, NSInteger errorCode))completion
 {
     NSString *file = [NSString stringWithFormat:@"%@/%@.ico", [CCUtility getDirectoryProviderStorageFileID:metadata.fileID], metadata.fileNameView];

+ 4 - 5
iOSClient/Trash/NCTrash.swift

@@ -216,15 +216,14 @@ class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDe
         
         let width = NCUtility.sharedInstance.getScreenWidthForPreview()
         let high = NCUtility.sharedInstance.getScreenHeightForPreview()
-        let serverUrl = appDelegate.activeUrl + tableTrash.filePath
+        let path = appDelegate.activeUrl + tableTrash.filePath + tableTrash.fileName
+        let file = CCUtility.getDirectoryProviderStorageFileID(tableTrash.fileID, fileNameView: tableTrash.fileName) + "/" + tableTrash.fileName + ".ico"
         
         let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: appDelegate.activeUser, withUserID: appDelegate.activeUserID, withPassword: appDelegate.activePassword, withUrl: appDelegate.activeUrl)
-
-        /*
-        ocNetworking?.downloadThumbnail(withFileID: tableTrash.fileID, fileName: tableTrash.fileName, fileNameView: tableTrash.fileName, serverUrl: serverUrl, withWidth: width, andHeight: high, completion: { (message, errorCodce) in
+        ocNetworking?.downloadThumbnail(withPath: path, file: file, withWidth: width, andHeight: high, completion: { (message, errorCode) in
             
         })
-        */
+        
     }
     
     // MARK: COLLECTIONVIEW METHODS