|
@@ -23,6 +23,7 @@
|
|
|
|
|
|
import UIKit
|
|
import UIKit
|
|
import NextcloudKit
|
|
import NextcloudKit
|
|
|
|
+import SVGKit
|
|
|
|
|
|
class NCUtilityGUI{
|
|
class NCUtilityGUI{
|
|
|
|
|
|
@@ -37,14 +38,14 @@ class NCUtilityGUI{
|
|
} else if !createPreviewMedia {
|
|
} else if !createPreviewMedia {
|
|
return nil
|
|
return nil
|
|
} else if createPreviewMedia && status >= NCGlobal.shared.metadataStatusNormal && classFile == NKCommon.typeClassFile.image.rawValue && FileManager().fileExists(atPath: filePath) {
|
|
} else if createPreviewMedia && status >= NCGlobal.shared.metadataStatusNormal && classFile == NKCommon.typeClassFile.image.rawValue && FileManager().fileExists(atPath: filePath) {
|
|
- if let image = UIImage(contentsOfFile: filePath), let image = image.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon), isAspectRation: true), let data = image.jpegData(compressionQuality: 0.5) {
|
|
|
|
|
|
+ if let image = UIImage(contentsOfFile: filePath), let image = image.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon)), let data = image.jpegData(compressionQuality: 0.5) {
|
|
do {
|
|
do {
|
|
try data.write(to: URL.init(fileURLWithPath: iconImagePath), options: .atomic)
|
|
try data.write(to: URL.init(fileURLWithPath: iconImagePath), options: .atomic)
|
|
imagePreview = image
|
|
imagePreview = image
|
|
} catch { }
|
|
} catch { }
|
|
}
|
|
}
|
|
} else if createPreviewMedia && status >= NCGlobal.shared.metadataStatusNormal && classFile == NKCommon.typeClassFile.video.rawValue && FileManager().fileExists(atPath: filePath) {
|
|
} else if createPreviewMedia && status >= NCGlobal.shared.metadataStatusNormal && classFile == NKCommon.typeClassFile.video.rawValue && FileManager().fileExists(atPath: filePath) {
|
|
- if let image = NCUtility.shared.imageFromVideo(url: URL(fileURLWithPath: filePath), at: 0), let image = image.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon), isAspectRation: true), let data = image.jpegData(compressionQuality: 0.5) {
|
|
|
|
|
|
+ if let image = NCUtility.shared.imageFromVideo(url: URL(fileURLWithPath: filePath), at: 0), let image = image.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon)), let data = image.jpegData(compressionQuality: 0.5) {
|
|
do {
|
|
do {
|
|
try data.write(to: URL.init(fileURLWithPath: iconImagePath), options: .atomic)
|
|
try data.write(to: URL.init(fileURLWithPath: iconImagePath), options: .atomic)
|
|
imagePreview = image
|
|
imagePreview = image
|
|
@@ -54,4 +55,31 @@ class NCUtilityGUI{
|
|
|
|
|
|
return imagePreview
|
|
return imagePreview
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ func getImageUserData(url: URL, fileName: String, size: CGFloat, completition: @escaping (_ image: UIImage?) -> () = { _ in }) {
|
|
|
|
+
|
|
|
|
+ let fileNamePath: String = CCUtility.getDirectoryUserData() + "/" + fileName + ".png"
|
|
|
|
+ let size = CGSize(width: size, height: size)
|
|
|
|
+
|
|
|
|
+ if !FileManager().fileExists(atPath: fileNamePath) {
|
|
|
|
+ NextcloudKit.shared.getPreview(url: url) { account, data, error in
|
|
|
|
+ guard let data = data else { return completition(nil) }
|
|
|
|
+ var image: UIImage?
|
|
|
|
+ if let uiImage = UIImage(data: data) {
|
|
|
|
+ image = uiImage.resizeImage(size: size)
|
|
|
|
+ } else if let svgImage = SVGKImage(data: data) {
|
|
|
|
+ svgImage.size = size
|
|
|
|
+ image = svgImage.uiImage
|
|
|
|
+ }
|
|
|
|
+ if let image = image {
|
|
|
|
+ do {
|
|
|
|
+ try image.pngData()?.write(to: URL(fileURLWithPath: fileNamePath), options: .atomic)
|
|
|
|
+ } catch { }
|
|
|
|
+ }
|
|
|
|
+ completition(image)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ completition(UIImage(contentsOfFile: fileNamePath))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|