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

test

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 жил өмнө
parent
commit
24a90da95d

+ 14 - 14
iOSClient/Networking/NCNetworking.swift

@@ -1407,21 +1407,21 @@ import Photos
 
     // MARK: - TEST API
 
-    public func getPreview(url: URL, options: NKRequestOptions = NKRequestOptions(), completion: @escaping (_ data: Data?) -> Void) {
-                
-        let headers = NKCommon.shared.getStandardHeaders(options: options)
-        
-        AF.request(url, method: .get, parameters: nil, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).response(queue: NKCommon.shared.backgroundQueue) { (response) in
-            debugPrint(response)
+    @available(iOS 13.0, *)
+    func getPreview(url: URL, options: NKRequestOptions = NKRequestOptions()) async throws -> Data? {
+
+        try await withUnsafeThrowingContinuation { continuation in
             
-            switch response.result {
-            case .failure( _):
-                completion(nil)
-            case .success( _):
-                if let data = response.data {
-                    completion(data)
-                } else {
-                    completion(nil)
+            let headers = NKCommon.shared.getStandardHeaders(options: options)
+            
+            AF.request(url, method: .get, parameters: nil, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).response(queue: NKCommon.shared.backgroundQueue) { (response) in
+                debugPrint(response)
+                
+                switch response.result {
+                case .failure(let error):
+                    continuation.resume(throwing: error)
+                case .success(let data):
+                    continuation.resume(returning: data)
                 }
             }
         }

+ 22 - 0
iOSClient/Networking/NCService.swift

@@ -275,6 +275,28 @@ class NCService: NSObject {
         NextcloudKit.shared.getDashboardWidget(options: options) { account, dashboardWidgets, data, error in
             if error == .success, let dashboardWidgets = dashboardWidgets  {
                 NCManageDatabase.shared.addDasboardWidget(account: account, dashboardWidgets: dashboardWidgets)
+                if #available(iOS 13.0, *) {
+                    for widget in dashboardWidgets {
+                        if let url = URL(string: widget.iconUrl) {
+                            NextcloudKit.shared.getPreview(url: url) { account, data, error in
+                                print("")
+                            }
+                            /*
+                            Task {
+                                do {
+                                    if let data = try await NCNetworking.shared.getPreview(url:url) {
+                                        if let name = widget.iconClass, let image = UIImage(data: data) {
+                                            print("")
+                                        }
+                                    }
+                                } catch {
+                                    print(error)
+                                }
+                            }
+                            */
+                        }
+                    }
+                }
             }
         }
     }