|
@@ -1209,96 +1209,6 @@
|
|
#pragma mark ===== Favorite =====
|
|
#pragma mark ===== Favorite =====
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
|
|
|
|
-- (void)listingFavoritesWithAccount:(NSString *)account 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 *autoUploadFileName = [[NCManageDatabase sharedInstance] getAccountAutoUploadFileName];
|
|
|
|
- NSString *autoUploadDirectory = [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:tableAccount.url];
|
|
|
|
- NSString *url = tableAccount.url;
|
|
|
|
- NSString *userID = tableAccount.userID;
|
|
|
|
- NSString *path = [url stringByAppendingString:k_dav];
|
|
|
|
-
|
|
|
|
- OCCommunication *communication = [OCNetworking sharedManager].sharedOCCommunication;
|
|
|
|
-
|
|
|
|
- [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:[CCUtility getPassword:account]];
|
|
|
|
- [communication setUserAgent:[CCUtility getUserAgent]];
|
|
|
|
- [communication listingFavorites:path folder:@"" 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];
|
|
|
|
-
|
|
|
|
- // Order by fileNamePath
|
|
|
|
- NSArray *itemsSortedArray = [items sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
|
|
|
|
-
|
|
|
|
- OCFileDto *record1 = obj1, *record2 = obj2;
|
|
|
|
-
|
|
|
|
- NSString *path1 = [[record1.filePath stringByAppendingString:record1.fileName] lowercaseString];
|
|
|
|
- NSString *path2 = [[record2.filePath stringByAppendingString:record2.fileName] lowercaseString];
|
|
|
|
-
|
|
|
|
- return [path1 compare:path2];
|
|
|
|
-
|
|
|
|
- }];
|
|
|
|
-
|
|
|
|
- for(OCFileDto *itemDto in itemsSortedArray) {
|
|
|
|
-
|
|
|
|
- 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;
|
|
|
|
-
|
|
|
|
- // Error
|
|
|
|
- if (errorCode == 503)
|
|
|
|
- message = NSLocalizedString(@"_server_error_retry_", nil);
|
|
|
|
- else
|
|
|
|
- message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
|
|
|
|
-
|
|
|
|
- completion(account, nil, message, errorCode);
|
|
|
|
- }];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
- (void)settingFavoriteWithAccount:(NSString *)account fileName:(NSString *)fileName favorite:(BOOL)favorite completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion
|
|
- (void)settingFavoriteWithAccount:(NSString *)account fileName:(NSString *)fileName favorite:(BOOL)favorite completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion
|
|
{
|
|
{
|
|
tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
|
|
tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
|