Ver código fonte

coding - test

marinofaggiana 3 anos atrás
pai
commit
d75ffb0421

+ 1 - 1
Nextcloud.xcodeproj/project.pbxproj

@@ -2905,7 +2905,7 @@
 			repositoryURL = "https://github.com/nextcloud/ios-communication-library/";
 			requirement = {
 				kind = revision;
-				revision = 8b9e2dbafe9f269bee9478c337bb36eff8bcba8b;
+				revision = 59409a7218007ce092aa7f3d1170ffaddad7041a;
 			};
 		};
 		F788ECC5263AAAF900ADC67F /* XCRemoteSwiftPackageReference "MarkdownKit" */ = {

+ 1 - 1
Nextcloud.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

@@ -105,7 +105,7 @@
         "repositoryURL": "https://github.com/nextcloud/ios-communication-library/",
         "state": {
           "branch": null,
-          "revision": "8b9e2dbafe9f269bee9478c337bb36eff8bcba8b",
+          "revision": "59409a7218007ce092aa7f3d1170ffaddad7041a",
           "version": null
         }
       },

+ 1 - 0
iOSClient/AppDelegate.swift

@@ -50,6 +50,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     @objc var activeViewController: UIViewController?
     var activeViewerVideo: NCViewerVideo?
     var mainTabBar: NCMainTabBar?
+    var activeMetadata: tableMetadata?
     
     var listFilesVC: [String:NCFiles] = [:]
     var listFavoriteVC: [String:NCFavorite] = [:]

+ 1 - 0
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -1079,6 +1079,7 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
         guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else { return }
         metadataTouch = metadata
         selectedIndexPath = indexPath
+        appDelegate.activeMetadata = metadata
         
         if isEditMode {
             if let index = selectOcId.firstIndex(of: metadata.ocId) {

+ 24 - 1
iOSClient/More/NCMore.swift

@@ -166,6 +166,15 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
         item.icon = "gear"
         item.url = "segueSettings"
         settingsMenu.append(item)
+        
+        // ITEM: Test API
+        if NCUtility.shared.isSimulator() {
+            item = NCCommunicationExternalSite()
+            item.name = "Test API"
+            item.icon = "swift"
+            item.url = "test"
+            settingsMenu.append(item)
+        }
 
         if (quotaMenu.count > 0) {
             let item = quotaMenu[0]
@@ -301,7 +310,6 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
 
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 
-        
         var item = NCCommunicationExternalSite()
 
         // change color selection and disclosure indicator
@@ -444,6 +452,21 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
             alertController.addAction(actionYes)
             alertController.addAction(actionNo)
             self.present(alertController, animated: true, completion: nil)
+            
+        } else if item.url == "test" {
+            
+            let fileId = appDelegate.activeMetadata?.fileId ?? "0"
+            
+            NCCommunication.shared.getDirectDownload(fileId: fileId) { account, url, errorCode, errorDescription in
+                print(url)
+            }
+            
+            
+            /*
+            NCNetworking.shared.getDirectDownload(urlBase: appDelegate.urlBase, username: appDelegate.user, password: appDelegate.password, fileId: appDelegate.activeMetadata?.fileId ?? "0") { a, b, c in
+                
+            }
+            */
         }
     }
 }

+ 10 - 13
iOSClient/Networking/NCNetworking.swift

@@ -1296,12 +1296,11 @@ import Queuer
     
     //MARK: - TEST API
         
-    /*
-    @objc public func getAppPassword(serverUrl: String, username: String, password: String, customUserAgent: String? = nil, completionHandler: @escaping (_ token: String?, _ errorCode: Int, _ errorDescription: String) -> Void) {
+    @objc public func getDirectDownload(urlBase: String, username: String, password: String, fileId: String, customUserAgent: String? = nil, completionHandler: @escaping (_ token: String?, _ errorCode: Int, _ errorDescription: String) -> Void) {
                 
-        let endpoint = "/ocs/v2.php/core/getapppassword"
+        let endpoint = "/ocs/v2.php/apps/dav/api/v1/direct"
         
-        let url:URLConvertible = try! (serverUrl + endpoint).asURL() as URLConvertible
+        let url:URLConvertible = try! (urlBase + endpoint).asURL() as URLConvertible
         var headers: HTTPHeaders = [.authorization(username: username, password: password)]
         if customUserAgent != nil {
             headers.update(.userAgent(customUserAgent!))
@@ -1309,15 +1308,13 @@ import Queuer
         //headers.update(.contentType("application/json"))
         headers.update(name: "OCS-APIRequest", value: "true")
                
-        var urlRequest: URLRequest
-        do {
-            try urlRequest = URLRequest(url: url, method: HTTPMethod(rawValue: "GET"), headers: headers)
-        } catch {
-            completionHandler(nil, error._code, error.localizedDescription)
-            return
-        }
+        let method = HTTPMethod(rawValue: "POST")
+
+        let parameters = [
+            "fileId": fileId,
+        ]
         
-        AF.request(urlRequest).validate(statusCode: 200..<300).response { (response) in
+        AF.request(url, method: method, parameters: parameters, headers: headers).validate(statusCode: 200..<300).response { (response) in
             debugPrint(response)
             
             switch response.result {
@@ -1332,5 +1329,5 @@ import Queuer
             }
         }
     }
-    */
+    
 }