|
@@ -704,131 +704,6 @@
|
|
|
[task resume];
|
|
|
}
|
|
|
|
|
|
-#pragma --------------------------------------------------------------------------------------------
|
|
|
-#pragma mark ===== Trash =====
|
|
|
-#pragma --------------------------------------------------------------------------------------------
|
|
|
-
|
|
|
-- (void)listingTrashWithAccount:(NSString *)account path:(NSString *)path serverUrl:(NSString *)serverUrl depth:(NSString *)depth completion:(void (^)(NSString *account, NSArray *items, 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 listingTrash:[serverUrl stringByAppendingString:path] depth:depth onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer) {
|
|
|
-
|
|
|
- // Check items > 0
|
|
|
- if ([items count] == 0) {
|
|
|
-
|
|
|
- [[NCContentPresenter shared] messageNotification:@"Server error" description:@"Read Folder WebDAV : [items NULL] please fix" delay:k_dismissAfterSecond type:messageTypeError errorCode:k_CCErrorInternalError];
|
|
|
- completion(account, nil, NSLocalizedString(@"Read Folder WebDAV : [items NULL] please fix", nil), k_CCErrorInternalError);
|
|
|
-
|
|
|
- } else {
|
|
|
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
- NSMutableArray *listTrash = [NSMutableArray new];
|
|
|
-
|
|
|
- //OCFileDto *itemDtoFolder = [items objectAtIndex:0];
|
|
|
-
|
|
|
- if ([items count] > 1) {
|
|
|
- for (NSUInteger i=1; i < [items count]; i++) {
|
|
|
-
|
|
|
- OCFileDto *itemDto = [items objectAtIndex:i];
|
|
|
- tableTrash *trash = [tableTrash new];
|
|
|
-
|
|
|
- trash.account = account;
|
|
|
- trash.date = [NSDate dateWithTimeIntervalSince1970:itemDto.date];
|
|
|
- trash.directory = itemDto.isDirectory;
|
|
|
- trash.fileId = itemDto.fileId;
|
|
|
- trash.fileName = itemDto.fileName;
|
|
|
- NSArray *array = [itemDto.filePath componentsSeparatedByString:path];
|
|
|
- long len = [[array objectAtIndex:0] length];
|
|
|
- trash.filePath = [itemDto.filePath substringFromIndex:len];
|
|
|
- trash.hasPreview = itemDto.hasPreview;
|
|
|
- trash.size = itemDto.size;
|
|
|
- trash.trashbinFileName = itemDto.trashbinFileName;
|
|
|
- trash.trashbinOriginalLocation = itemDto.trashbinOriginalLocation;
|
|
|
- trash.trashbinDeletionTime = [NSDate dateWithTimeIntervalSince1970:itemDto.trashbinDeletionTime];
|
|
|
-
|
|
|
- NSDictionary *results = [[NCCommunicationCommon shared] objcGetInternalContenTypeWithFileName:trash.trashbinFileName contentType:@"" directory:itemDto.isDirectory];
|
|
|
-
|
|
|
- trash.contentType = results[@"contentType"];
|
|
|
- trash.iconName = results[@"iconName"];
|
|
|
- trash.typeFile = results[@"typeFile"];
|
|
|
-
|
|
|
- [listTrash addObject:trash];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- completion(account, listTrash, 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)emptyTrashWithAccount:(NSString *)account completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion
|
|
|
-{
|
|
|
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
|
|
|
- if (tableAccount == nil) {
|
|
|
- completion(account, NSLocalizedString(@"_error_user_not_available_", nil), k_CCErrorUserNotAvailble);
|
|
|
- } else if ([CCUtility getPassword:account].length == 0) {
|
|
|
- completion(account, NSLocalizedString(@"_bad_username_password_", nil), kOCErrorServerUnauthorized);
|
|
|
- } else if ([CCUtility getCertificateError:account]) {
|
|
|
- completion(account, NSLocalizedString(@"_ssl_certificate_untrusted_", nil), NSURLErrorServerCertificateUntrusted);
|
|
|
- }
|
|
|
-
|
|
|
- NSString *path = [NSString stringWithFormat:@"%@%@/trashbin/%@/trash", tableAccount.url, k_dav, tableAccount.userID];
|
|
|
-
|
|
|
- OCCommunication *communication = [OCNetworking sharedManager].sharedOCCommunication;
|
|
|
-
|
|
|
- [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:[CCUtility getPassword:account]];
|
|
|
- [communication setUserAgent:[CCUtility getUserAgent]];
|
|
|
- [communication emptyTrash:path onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
|
|
|
-
|
|
|
- completion(account, 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, message, errorCode);
|
|
|
- }];
|
|
|
-}
|
|
|
-
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
|
#pragma mark ===== Comments =====
|
|
|
#pragma --------------------------------------------------------------------------------------------
|