Ver Fonte

alignment 4.0.5

marinofaggiana há 3 anos atrás
pai
commit
911ae2e728

+ 57 - 34
Share/NCShareExtension.swift

@@ -766,9 +766,16 @@ extension NCShareExtension {
                                 conuter += 1
                                 
                                 if let url = item as? NSURL {
-                                    fileNameOriginal = url.lastPathComponent!
+                                    if FileManager.default.fileExists(atPath: url.path ?? "") {
+                                        fileNameOriginal = url.lastPathComponent!
+                                    } else if url.scheme?.lowercased().contains("http") == true ||  url.scheme?.lowercased().contains("https") == true {
+                                        fileNameOriginal = "\(dateFormatter.string(from: Date()))\(conuter).html"
+                                    } else {
+                                        fileNameOriginal = "\(dateFormatter.string(from: Date()))\(conuter)"
+                                    }
                                 }
                                 
+                                
                                 if error == nil {
                                                                         
                                     if let image = item as? UIImage {
@@ -795,46 +802,59 @@ extension NCShareExtension {
                                          
                                             print("Error image nil")
                                         }
+                                        
+                                        if index + 1 == attachments.count {
+                                            completion(filesName, outError)
+                                        }
                                     }
                                     
                                     if let url = item as? URL {
                                         
-                                        print("item as url: \(String(describing: item))")
-                                        
-                                        if fileNameOriginal != nil {
-                                            fileName =  fileNameOriginal!
-                                        } else {
-                                            let ext = url.pathExtension
-                                            fileName = "\(dateFormatter.string(from: Date()))\(conuter)." + ext
-                                        }
-                                        
-                                        let filenamePath = NSTemporaryDirectory() + fileName
-                                      
-                                        do {
-                                            try FileManager.default.removeItem(atPath: filenamePath)
-                                        }
-                                        catch { }
-                                        
-                                        do {
-                                            try FileManager.default.copyItem(atPath: url.path, toPath:filenamePath)
+                                        let task = URLSession.shared.downloadTask(with: url) { localURL, urlResponse, error in
                                             
-                                            do {
-                                                let attr : NSDictionary? = try FileManager.default.attributesOfItem(atPath: filenamePath) as NSDictionary?
+                                            if let localURL = localURL {
+                                                
+                                                if fileNameOriginal != nil {
+                                                    fileName =  fileNameOriginal!
+                                                } else {
+                                                    let ext = url.pathExtension
+                                                    fileName = "\(dateFormatter.string(from: Date()))\(conuter)." + ext
+                                                }
                                                 
-                                                if let _attr = attr {
-                                                    if _attr.fileSize() > 0 {
+                                                let filenamePath = NSTemporaryDirectory() + fileName
+                                              
+                                                do {
+                                                    try FileManager.default.removeItem(atPath: filenamePath)
+                                                }
+                                                catch { }
+                                                
+                                                do {
+                                                    try FileManager.default.copyItem(atPath: localURL.path, toPath:filenamePath)
+                                                    
+                                                    do {
+                                                        let attr : NSDictionary? = try FileManager.default.attributesOfItem(atPath: filenamePath) as NSDictionary?
+                                                        
+                                                        if let _attr = attr {
+                                                            if _attr.fileSize() > 0 {
+                                                                
+                                                                filesName.append(fileName)
+                                                            }
+                                                        }
                                                         
-                                                        filesName.append(fileName)
+                                                    } catch let error {
+                                                        outError = error
                                                     }
+                                                    
+                                                } catch let error {
+                                                    outError = error
                                                 }
-                                                
-                                            } catch let error {
-                                                outError = error
                                             }
                                             
-                                        } catch let error {
-                                            outError = error
+                                            if index + 1 == attachments.count {
+                                                completion(filesName, outError)
+                                            }
                                         }
+                                        task.resume()
                                     }
                                     
                                     if let data = item as? Data {
@@ -859,6 +879,10 @@ extension NCShareExtension {
                                                                                 
                                             filesName.append(fileName)
                                         }
+                                        
+                                        if index + 1 == attachments.count {
+                                            completion(filesName, outError)
+                                        }
                                     }
                                     
                                     if let data = item as? NSString {
@@ -874,12 +898,11 @@ extension NCShareExtension {
                                         
                                             filesName.append(fileName)
                                         }
+                                        
+                                        if index + 1 == attachments.count {
+                                            completion(filesName, outError)
+                                        }
                                     }
-                                    
-                                    if index + 1 == attachments.count {
-                                        completion(filesName, outError)
-                                    }
-                                    
                                 } else {
                                     completion( filesName, error)
                                 }

+ 1 - 1
iOSClient/Brand/Share.plist

@@ -42,7 +42,7 @@
 				<key>NSExtensionActivationSupportsText</key>
 				<true/>
 				<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
-				<integer>0</integer>
+				<integer>1</integer>
 			</dict>
 		</dict>
 		<key>NSExtensionMainStoryboard</key>

+ 6 - 1
iOSClient/BrowserWeb/NCBrowserWeb.swift

@@ -63,7 +63,12 @@ class NCBrowserWeb: UIViewController {
             buttonExit.setImage(image, for: .normal)
         }
         
-        loadWebPage(webView: webView!, url: URL(string: urlBase)!)
+        if let url = URL(string: urlBase) {
+            loadWebPage(webView: webView!, url: url)
+        } else {
+            let url = URL(fileURLWithPath: urlBase)
+            loadWebPage(webView: webView!, url: url)
+        }
     }
     
     override func viewWillAppear(_ animated: Bool) {

+ 14 - 0
iOSClient/Viewer/NCViewer.swift

@@ -187,6 +187,20 @@ class NCViewer: NSObject {
                 
                 return
             }
+            
+            if metadata.contentType == "text/html" {
+                
+                if let navigationController = viewController.navigationController {
+                    
+                    let viewController = UIStoryboard(name: "NCBrowserWeb", bundle: nil).instantiateInitialViewController() as! NCBrowserWeb
+                    viewController.urlBase = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)
+                    viewController.isHiddenButtonExit = true
+
+                    navigationController.pushViewController(viewController, animated: true)
+                }
+
+                return
+            }
         }
         
         // OTHER