Эх сурвалжийг харах

Add the possibility of webDAV search with contentType

Marino Faggiana 7 жил өмнө
parent
commit
c2644e86e3

+ 2 - 1
iOSClient/Actions/CCActions.swift

@@ -296,7 +296,7 @@ class CCActions: NSObject {
     // MARK: Search
     // --------------------------------------------------------------------------------------------
     
-    @objc func search(_ serverUrl: String, fileName: String, depth: String, date: Date?, selector: String, delegate: AnyObject) {
+    @objc func search(_ serverUrl: String, fileName: String, depth: String, date: Date?, contentType: String?, selector: String, delegate: AnyObject) {
         
         guard let directoryID = NCManageDatabase.sharedInstance.getDirectoryID(serverUrl) else {
             return
@@ -307,6 +307,7 @@ class CCActions: NSObject {
         let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
         
         metadataNet.action = actionSearch
+        metadataNet.contentType = contentType
         metadataNet.date = date
         metadataNet.delegate = delegate
         metadataNet.directoryID = directoryID

+ 4 - 0
iOSClient/AppDelegate.m

@@ -317,6 +317,10 @@
         [[CCSynchronize sharedSynchronize] readFileForFolder:fileName serverUrl:serverUrl selector:selectorReadFileFolder];        
     }
     
+    //TEST
+    //[[CCActions sharedInstance] search:@"" fileName:@"" depth:@"infinity" date:nil contentType:@"image/%" selector:selectorSearchContentType delegate:self];
+
+    
     // Execute : after 1 sec.
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
         

+ 2 - 1
iOSClient/CCGlobal.h

@@ -175,7 +175,8 @@ extern NSString *const flowEndpoint;
 #define selectorRename                                  @"rename"
 #define selectorSave                                    @"save"
 #define selectorShare                                   @"share"
-#define selectorSearch                                  @"search"
+#define selectorSearchFiles                             @"searchFiles"
+#define selectorSearchContentType                       @"searchContentType"
 #define selectorUnshare                                 @"unshare"
 #define selectorUpdateShare                             @"updateShare"
 #define selectorUploadAutoUpload                        @"uploadAutoUpload"

+ 74 - 35
iOSClient/Library/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m

@@ -276,41 +276,80 @@ NSString const *OCWebDAVModificationDateKey	= @"modificationdate";
     
     NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:path parameters:nil];
     
-    body = [NSString stringWithFormat: @""
-            "<?xml version=\"1.0\"?>"
-            "<d:searchrequest xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\">"
-                "<d:basicsearch>"
-                    "<d:select>"
-                        "<d:prop>"
-                            "<d:getlastmodified />"
-                            "<d:getetag />"
-                            "<d:getcontenttype />"
-                            "<d:resourcetype/>"
-                            "<d:getcontentlength />"
-                            "<oc:fileid/>"
-                            "<oc:id/>"
-                            "<oc:permissions />"
-                            "<oc:size />"
-                            "<oc:favorite/>"
-                            "<nc:is-encrypted/>"
-                        "</d:prop>"
-                    "</d:select>"
-                    "<d:from>"
-                        "<d:scope>"
-                            "<d:href>/files/%@%@</d:href>"
-                            "<d:depth>infinity</d:depth>"
-                        "</d:scope>"
-                    "</d:from>"
-                    "<d:where>"
-                        "<d:like>"
-                            //"<d:prop><d:getcontenttype/></d:prop>"
-                            //"<d:literal>image/%</d:literal>"
-                            "<d:prop><d:displayname/></d:prop>"
-                            "<d:literal>%@</d:literal>"
-                        "</d:like>"
-                    "</d:where>"
-                "</d:basicsearch>"
-            "</d:searchrequest>", userID, folder, fileName];
+    if (contentType) {
+        
+        body = [NSString stringWithFormat: @""
+        "<?xml version=\"1.0\"?>"
+        "<d:searchrequest xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\">"
+            "<d:basicsearch>"
+                "<d:select>"
+                    "<d:prop>"
+                        "<d:getlastmodified />"
+                        "<d:getetag />"
+                        "<d:getcontenttype />"
+                        "<d:resourcetype/>"
+                        "<d:getcontentlength />"
+                        "<oc:fileid/>"
+                        "<oc:id/>"
+                        "<oc:permissions />"
+                        "<oc:size />"
+                        "<oc:favorite/>"
+                        "<nc:is-encrypted/>"
+                    "</d:prop>"
+                "</d:select>"
+                "<d:from>"
+                    "<d:scope>"
+                        "<d:href>/files/%@</d:href>"
+                        "<d:depth>infinity</d:depth>"
+                    "</d:scope>"
+                "</d:from>"
+                "<d:where>"
+                    "<d:like>"
+                        "<d:prop><d:getcontenttype/></d:prop>"
+                        "<d:literal>%@</d:literal>"
+                    "</d:like>"
+                "</d:where>"
+            "</d:basicsearch>"
+        "</d:searchrequest>", userID, contentType];
+        
+    } else {
+        
+        body = [NSString stringWithFormat: @""
+        "<?xml version=\"1.0\"?>"
+        "<d:searchrequest xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\">"
+            "<d:basicsearch>"
+                "<d:select>"
+                    "<d:prop>"
+                        "<d:getlastmodified />"
+                        "<d:getetag />"
+                        "<d:getcontenttype />"
+                        "<d:resourcetype/>"
+                        "<d:getcontentlength />"
+                        "<oc:fileid/>"
+                        "<oc:id/>"
+                        "<oc:permissions />"
+                        "<oc:size />"
+                        "<oc:favorite/>"
+                        "<nc:is-encrypted/>"
+                    "</d:prop>"
+                "</d:select>"
+                "<d:from>"
+                    "<d:scope>"
+                        "<d:href>/files/%@%@</d:href>"
+                        "<d:depth>infinity</d:depth>"
+                    "</d:scope>"
+                "</d:from>"
+                "<d:where>"
+                    "<d:like>"
+                        //"<d:prop><d:getcontenttype/></d:prop>"
+                        //"<d:literal>image/%</d:literal>"
+                        "<d:prop><d:displayname/></d:prop>"
+                        "<d:literal>%@</d:literal>"
+                    "</d:like>"
+                "</d:where>"
+            "</d:basicsearch>"
+        "</d:searchrequest>", userID, folder, fileName];
+    }
     
     [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
     [request setValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];

+ 2 - 2
iOSClient/Main/CCMain.m

@@ -1932,7 +1932,7 @@
 {
     NSString *home = [CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl];
     
-    [[CCActions sharedInstance] search:home fileName:_searchFileName depth:@"infinity" date:nil selector:selectorSearch delegate:self];
+    [[CCActions sharedInstance] search:home fileName:_searchFileName depth:@"infinity" date:nil contentType:nil selector:selectorSearchFiles delegate:self];
 
     _noFilesSearchTitle = @"";
     _noFilesSearchDescription = NSLocalizedString(@"_search_in_progress_", nil);
@@ -1970,7 +1970,7 @@
             
         metadataNet.account = appDelegate.activeAccount;
         metadataNet.directoryID = directoryID;
-        metadataNet.selector = selectorSearch;
+        metadataNet.selector = selectorSearchFiles;
         metadataNet.serverUrl = _serverUrl;
 
         [self readFolderSuccess:metadataNet metadataFolder:nil metadatas:_searchResultMetadatas];