|
@@ -692,340 +692,6 @@
|
|
|
}];
|
|
|
}
|
|
|
|
|
|
-- (void)searchWithAccount:(NSString *)account fileName:(NSString *)fileName serverUrl:(NSString *)serverUrl contentType:(NSArray *)contentType lteDateLastModified:(NSDate *)lteDateLastModified gteDateLastModified:(NSDate *)gteDateLastModified depth:(NSString *)depth completion:(void(^)(NSString *account, NSArray *metadatas, NSString *message, NSInteger errorCode))completion
|
|
|
-{
|
|
|
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
|
|
|
- if (tableAccount == nil) {
|
|
|
- completion(account, nil, NSLocalizedString(@"_error_user_not_available_", nil), k_CCErrorUserNotAvailble);
|
|
|
- } else if ([CCUtility getPassword:account].length == 0) {
|
|
|
- completion(account, nil, NSLocalizedString(@"_bad_username_password_", nil), kOCErrorServerUnauthorized);
|
|
|
- } else if ([CCUtility getCertificateError:account]) {
|
|
|
- completion(account, nil, NSLocalizedString(@"_ssl_certificate_untrusted_", nil), NSURLErrorServerCertificateUntrusted);
|
|
|
- }
|
|
|
-
|
|
|
- NSString *path = [tableAccount.url stringByAppendingString:k_dav];
|
|
|
- NSString *folder = [serverUrl stringByReplacingOccurrencesOfString:[CCUtility getHomeServerUrlActiveUrl:tableAccount.url] withString:@""];
|
|
|
- NSString *lteDateLastModifiedString;
|
|
|
- NSString *gteDateLastModifiedString;
|
|
|
- NSString *autoUploadFileName = [[NCManageDatabase sharedInstance] getAccountAutoUploadFileName];
|
|
|
- NSString *autoUploadDirectory = [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:tableAccount.url];
|
|
|
- NSString *url = tableAccount.url;
|
|
|
- NSString *userID = tableAccount.userID;
|
|
|
-
|
|
|
- if (lteDateLastModified) {
|
|
|
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
|
|
- NSLocale *enUSPOSIXLocale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
|
|
|
- [dateFormatter setLocale:enUSPOSIXLocale];
|
|
|
- [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
|
|
|
- lteDateLastModifiedString = [dateFormatter stringFromDate:lteDateLastModified];
|
|
|
- }
|
|
|
-
|
|
|
- if (gteDateLastModified) {
|
|
|
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
|
|
- NSLocale *enUSPOSIXLocale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
|
|
|
- [dateFormatter setLocale:enUSPOSIXLocale];
|
|
|
- [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
|
|
|
- gteDateLastModifiedString = [dateFormatter stringFromDate:gteDateLastModified];
|
|
|
- }
|
|
|
-
|
|
|
- OCCommunication *communication = [OCNetworking sharedManager].sharedOCCommunication;
|
|
|
-
|
|
|
- [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:[CCUtility getPassword:account]];
|
|
|
- [communication setUserAgent:[CCUtility getUserAgent]];
|
|
|
- [communication search:path folder:folder fileName: [NSString stringWithFormat:@"%%%@%%", fileName] depth:depth lteDateLastModified:lteDateLastModifiedString gteDateLastModified:gteDateLastModifiedString contentType:contentType withUserSessionToken:nil onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token) {
|
|
|
-
|
|
|
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
- NSMutableArray *metadatas = [NSMutableArray new];
|
|
|
- BOOL showHiddenFiles = [CCUtility getShowHiddenFiles];
|
|
|
-
|
|
|
- for (OCFileDto *itemDto in items) {
|
|
|
-
|
|
|
- NSString *serverUrl;
|
|
|
- BOOL isFolderEncrypted;
|
|
|
-
|
|
|
- NSString *fileName = [itemDto.fileName stringByReplacingOccurrencesOfString:@"/" withString:@""];
|
|
|
-
|
|
|
- // Skip hidden files
|
|
|
- if (fileName.length > 0) {
|
|
|
- if (!showHiddenFiles && [[fileName substringToIndex:1] isEqualToString:@"."])
|
|
|
- continue;
|
|
|
- } else
|
|
|
- continue;
|
|
|
-
|
|
|
- NSRange firstInstance = [itemDto.filePath rangeOfString:[NSString stringWithFormat:@"%@/files/%@", k_dav, userID]];
|
|
|
- NSString *serverPath = [itemDto.filePath substringFromIndex:firstInstance.length+firstInstance.location+1];
|
|
|
- if ([serverPath hasSuffix:@"/"]) serverPath = [serverPath substringToIndex:[serverPath length] - 1];
|
|
|
- serverUrl = [CCUtility stringAppendServerUrl:[url stringByAppendingString:k_webDAV] addFileName:serverPath];
|
|
|
-
|
|
|
- if (itemDto.isDirectory) {
|
|
|
- (void)[[NCManageDatabase sharedInstance] addDirectoryWithEncrypted:itemDto.isEncrypted favorite:itemDto.isFavorite ocId:itemDto.ocId permissions:itemDto.permissions serverUrl:[NSString stringWithFormat:@"%@/%@", serverUrl, fileName] richWorkspace:nil account:account];
|
|
|
- }
|
|
|
-
|
|
|
- isFolderEncrypted = [CCUtility isFolderEncrypted:serverUrl account:account];
|
|
|
-
|
|
|
- [metadatas addObject:[CCUtility trasformedOCFileToCCMetadata:itemDto fileName:itemDto.fileName serverUrl:serverUrl autoUploadFileName:autoUploadFileName autoUploadDirectory:autoUploadDirectory account:account isFolderEncrypted:isFolderEncrypted]];
|
|
|
- }
|
|
|
-
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- completion(account, metadatas, nil, 0);
|
|
|
- });
|
|
|
- });
|
|
|
- } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer) {
|
|
|
-
|
|
|
- NSString *message;
|
|
|
- NSInteger errorCode = response.statusCode;
|
|
|
-
|
|
|
- if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
|
|
|
- errorCode = error.code;
|
|
|
-
|
|
|
- // Server Unauthorized
|
|
|
- //if (errorCode == kOCErrorServerUnauthorized || errorCode == kOCErrorServerForbidden) {
|
|
|
- // [[OCNetworking sharedManager] checkRemoteUser:account function:@"search" errorCode:errorCode];
|
|
|
- //} else if (errorCode == NSURLErrorServerCertificateUntrusted) {
|
|
|
- // [CCUtility setCertificateError:account error:YES];
|
|
|
- //}
|
|
|
-
|
|
|
- // Error
|
|
|
- if (errorCode == 503) {
|
|
|
- message = NSLocalizedString(@"_server_error_retry_", nil);
|
|
|
- } else {
|
|
|
- message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
|
|
|
- }
|
|
|
-
|
|
|
- completion(account, nil, message, errorCode);
|
|
|
- }];
|
|
|
-}
|
|
|
-
|
|
|
-- (void)searchWithAccount:(NSString *)account folder:(NSString *)folder fileName:(NSString *)fileName dateLastModified:(NSDate *)dateLastModified numberOfItem:(NSInteger)numberOfItem completion:(void(^)(NSString *account, NSArray *metadatas, NSString *message, NSInteger errorCode))completion
|
|
|
-{
|
|
|
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
|
|
|
- if (tableAccount == nil) {
|
|
|
- completion(account, nil, NSLocalizedString(@"_error_user_not_available_", nil), k_CCErrorUserNotAvailble);
|
|
|
- } else if ([CCUtility getPassword:account].length == 0) {
|
|
|
- completion(account, nil, NSLocalizedString(@"_bad_username_password_", nil), kOCErrorServerUnauthorized);
|
|
|
- } else if ([CCUtility getCertificateError:account]) {
|
|
|
- completion(account, nil, NSLocalizedString(@"_ssl_certificate_untrusted_", nil), NSURLErrorServerCertificateUntrusted);
|
|
|
- }
|
|
|
-
|
|
|
- NSString *path = [tableAccount.url stringByAppendingString:k_dav];
|
|
|
-
|
|
|
- folder = [folder stringByReplacingOccurrencesOfString:[CCUtility getHomeServerUrlActiveUrl:tableAccount.url] withString:@""];
|
|
|
- fileName = [fileName stringByAppendingString:@"%"];
|
|
|
-
|
|
|
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
|
|
- NSLocale *enUSPOSIXLocale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
|
|
|
- [dateFormatter setLocale:enUSPOSIXLocale];
|
|
|
- [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
|
|
|
- NSString *dateLastModifiedString = [dateFormatter stringFromDate:dateLastModified];
|
|
|
-
|
|
|
- OCCommunication *communication = [OCNetworking sharedManager].sharedOCCommunication;
|
|
|
-
|
|
|
- [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:[CCUtility getPassword:account]];
|
|
|
- [communication setUserAgent:[CCUtility getUserAgent]];
|
|
|
- [communication search:path folder:folder fileName:fileName dateLastModified:dateLastModifiedString numberOfItem:numberOfItem withUserSessionToken:nil onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token) {
|
|
|
-
|
|
|
- completion(account, nil, nil, 0);
|
|
|
-
|
|
|
- } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer) {
|
|
|
-
|
|
|
- NSString *message;
|
|
|
- NSInteger errorCode = response.statusCode;
|
|
|
-
|
|
|
- if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
|
|
|
- errorCode = error.code;
|
|
|
-
|
|
|
- // Server Unauthorized
|
|
|
- //if (errorCode == kOCErrorServerUnauthorized || errorCode == kOCErrorServerForbidden) {
|
|
|
- // [[OCNetworking sharedManager] checkRemoteUser:account function:@"search" errorCode:errorCode];
|
|
|
- //} else if (errorCode == NSURLErrorServerCertificateUntrusted) {
|
|
|
- // [CCUtility setCertificateError:account error:YES];
|
|
|
- //}
|
|
|
-
|
|
|
- // Error
|
|
|
- if (errorCode == 503) {
|
|
|
- message = NSLocalizedString(@"_server_error_retry_", nil);
|
|
|
- } else {
|
|
|
- message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
|
|
|
- }
|
|
|
-
|
|
|
- completion(account, nil, message, errorCode);
|
|
|
- }];
|
|
|
-}
|
|
|
-
|
|
|
-#pragma --------------------------------------------------------------------------------------------
|
|
|
-#pragma mark ===== downloadPreview =====
|
|
|
-#pragma --------------------------------------------------------------------------------------------
|
|
|
-
|
|
|
-/*
|
|
|
- - (void)downloadThumbnailWithMetadata:(tableMetadata*)metadata withWidth:(CGFloat)width andHeight:(CGFloat)height completion:(void (^)(NSString *message, NSInteger errorCode))completion
|
|
|
- {
|
|
|
- NSString *file = [NSString stringWithFormat:@"%@/%@.ico", [CCUtility getDirectoryProviderStorageocId:metadata.ocId], metadata.fileNameView];
|
|
|
-
|
|
|
- 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:[CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:metadata.serverUrl activeUrl:_activeUrl] 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)downloadPreviewWithAccount:(NSString *)account metadata:(tableMetadata*)metadata withWidth:(CGFloat)width andHeight:(CGFloat)height completion:(void (^)(NSString *account, UIImage *image, NSString *message, NSInteger errorCode))completion
|
|
|
-{
|
|
|
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
|
|
|
- if (tableAccount == nil) {
|
|
|
- completion(account, nil, NSLocalizedString(@"_error_user_not_available_", nil), k_CCErrorUserNotAvailble);
|
|
|
- } else if ([CCUtility getPassword:account].length == 0) {
|
|
|
- completion(account, nil, NSLocalizedString(@"_bad_username_password_", nil), kOCErrorServerUnauthorized);
|
|
|
- } else if ([CCUtility getCertificateError:account]) {
|
|
|
- completion(account, nil, NSLocalizedString(@"_ssl_certificate_untrusted_", nil), NSURLErrorServerCertificateUntrusted);
|
|
|
- }
|
|
|
-
|
|
|
- NSString *file = [NSString stringWithFormat:@"%@/%@.ico", [CCUtility getDirectoryProviderStorageOcId:metadata.ocId], metadata.fileNameView];
|
|
|
-
|
|
|
- OCCommunication *communication = [OCNetworking sharedManager].sharedOCCommunication;
|
|
|
-
|
|
|
- [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:[CCUtility getPassword:account]];
|
|
|
- [communication setUserAgent:[CCUtility getUserAgent]];
|
|
|
- [communication getRemotePreviewByServer:tableAccount.url ofFilePath:[CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:metadata.serverUrl activeUrl:tableAccount.url] withWidth:width andHeight:height andA:1 andMode:@"cover" path:@"" onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSData *preview, NSString *redirectedServer) {
|
|
|
-
|
|
|
- [preview writeToFile:file atomically:YES];
|
|
|
-
|
|
|
- completion(account, [UIImage imageWithData:preview], 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(account, nil, message, errorCode);
|
|
|
- }];
|
|
|
-}
|
|
|
-
|
|
|
-- (void)downloadPreviewWithAccount:(NSString *)account serverPath:(NSString *)serverPath fileNamePath:(NSString *)fileNamePath completion:(void (^)(NSString *account, UIImage *image, NSString *message, NSInteger errorCode))completion
|
|
|
-{
|
|
|
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
|
|
|
- if (tableAccount == nil) {
|
|
|
- completion(account, nil, NSLocalizedString(@"_error_user_not_available_", nil), k_CCErrorUserNotAvailble);
|
|
|
- } else if ([CCUtility getPassword:account].length == 0) {
|
|
|
- completion(account, nil, NSLocalizedString(@"_bad_username_password_", nil), kOCErrorServerUnauthorized);
|
|
|
- } else if ([CCUtility getCertificateError:account]) {
|
|
|
- completion(account, nil, NSLocalizedString(@"_ssl_certificate_untrusted_", nil), NSURLErrorServerCertificateUntrusted);
|
|
|
- }
|
|
|
-
|
|
|
- OCCommunication *communication = [OCNetworking sharedManager].sharedOCCommunication;
|
|
|
-
|
|
|
- [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:[CCUtility getPassword:account]];
|
|
|
- [communication setUserAgent:[CCUtility getUserAgent]];
|
|
|
- [communication getRemotePreviewByServer:tableAccount.url ofFilePath:@"" withWidth:0 andHeight:0 andA:0 andMode:@"" path:serverPath onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSData *preview, NSString *redirectedServer) {
|
|
|
-
|
|
|
- [preview writeToFile:fileNamePath atomically:YES];
|
|
|
-
|
|
|
- completion(account, [UIImage imageWithData:preview], 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(account, nil, message, errorCode);
|
|
|
- }];
|
|
|
-}
|
|
|
-
|
|
|
-- (void)downloadPreviewTrashWithAccount:(NSString *)account fileId:(NSString *)fileId size:(NSString *)size fileName:(NSString *)fileName completion:(void (^)(NSString *account, UIImage *image, NSString *message, NSInteger errorCode))completion
|
|
|
-{
|
|
|
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
|
|
|
- if (tableAccount == nil) {
|
|
|
- completion(account, nil, NSLocalizedString(@"_error_user_not_available_", nil), k_CCErrorUserNotAvailble);
|
|
|
- } else if ([CCUtility getPassword:account].length == 0) {
|
|
|
- completion(account, nil, NSLocalizedString(@"_bad_username_password_", nil), kOCErrorServerUnauthorized);
|
|
|
- } else if ([CCUtility getCertificateError:account]) {
|
|
|
- completion(account, nil, NSLocalizedString(@"_ssl_certificate_untrusted_", nil), NSURLErrorServerCertificateUntrusted);
|
|
|
- }
|
|
|
-
|
|
|
- NSString *file = [NSString stringWithFormat:@"%@/%@.ico", [CCUtility getDirectoryProviderStorageOcId:fileId], fileName];
|
|
|
-
|
|
|
- if ([[NSFileManager defaultManager] fileExistsAtPath:file]) {
|
|
|
-
|
|
|
- completion(account, [UIImage imageWithContentsOfFile:file], nil, 0);
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- OCCommunication *communication = [OCNetworking sharedManager].sharedOCCommunication;
|
|
|
-
|
|
|
- [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:[CCUtility getPassword:account]];
|
|
|
- [communication setUserAgent:[CCUtility getUserAgent]];
|
|
|
- [communication getRemotePreviewTrashByServer:tableAccount.url ofFileId:fileId size:size onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSData *preview, NSString *redirectedServer) {
|
|
|
-
|
|
|
- [preview writeToFile:file atomically:YES];
|
|
|
-
|
|
|
- completion(account, [UIImage imageWithData:preview], 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(account, nil, message, errorCode);
|
|
|
- }];
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
|
#pragma mark ===== Share =====
|
|
|
#pragma --------------------------------------------------------------------------------------------
|