|
@@ -1345,6 +1345,49 @@
|
|
|
}];
|
|
|
}
|
|
|
|
|
|
+- (void)readShareWithAccount:(NSString *)account path:(NSString *)path 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 readSharedByServer:[tableAccount.url stringByAppendingString:@"/"] andPath:path onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSArray *listOfShared, NSString *redirectedServer) {
|
|
|
+ completion(account, listOfShared, 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;
|
|
|
+
|
|
|
+ // Server Unauthorized
|
|
|
+ if (errorCode == kOCErrorServerUnauthorized) {
|
|
|
+ [CCUtility setPassword:account password:nil];
|
|
|
+ } 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)shareWithAccount:(NSString *)account fileName:(NSString *)fileName password:(NSString *)password permission:(NSInteger)permission hideDownload:(BOOL)hideDownload completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion
|
|
|
{
|
|
|
tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
|