NCUtility.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. //
  2. // NCUtility.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 25/06/18.
  6. // Copyright © 2018 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import Foundation
  24. import SVGKit
  25. import KTVHTTPCache
  26. import NCCommunication
  27. import PDFKit
  28. class NCUtility: NSObject {
  29. @objc static let shared: NCUtility = {
  30. let instance = NCUtility()
  31. return instance
  32. }()
  33. let activityIndicator = UIActivityIndicatorView(style: .whiteLarge)
  34. @objc func getWebDAV(account: String) -> String {
  35. return NCManageDatabase.sharedInstance.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesWebDavRoot) ?? "remote.php/webdav"
  36. }
  37. @objc func getDAV() -> String {
  38. return "remote.php/dav"
  39. }
  40. @objc func getHomeServer(urlBase: String, account: String) -> String {
  41. return urlBase + "/" + self.getWebDAV(account: account)
  42. }
  43. @objc func createFileName(_ fileName: String, serverUrl: String, account: String) -> String {
  44. var resultFileName = fileName
  45. var exitLoop = false
  46. while exitLoop == false {
  47. if NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "fileNameView == %@ AND serverUrl == %@ AND account == %@", resultFileName, serverUrl, account)) != nil {
  48. var name = NSString(string: resultFileName).deletingPathExtension
  49. let ext = NSString(string: resultFileName).pathExtension
  50. let characters = Array(name)
  51. if characters.count < 2 {
  52. if ext == "" {
  53. resultFileName = name + " " + "1"
  54. } else {
  55. resultFileName = name + " " + "1" + "." + ext
  56. }
  57. } else {
  58. let space = characters[characters.count-2]
  59. let numChar = characters[characters.count-1]
  60. var num = Int(String(numChar))
  61. if (space == " " && num != nil) {
  62. name = String(name.dropLast())
  63. num = num! + 1
  64. if ext == "" {
  65. resultFileName = name + "\(num!)"
  66. } else {
  67. resultFileName = name + "\(num!)" + "." + ext
  68. }
  69. } else {
  70. if ext == "" {
  71. resultFileName = name + " " + "1"
  72. } else {
  73. resultFileName = name + " " + "1" + "." + ext
  74. }
  75. }
  76. }
  77. } else {
  78. exitLoop = true
  79. }
  80. }
  81. return resultFileName
  82. }
  83. @objc func isEncryptedMetadata(_ metadata: tableMetadata) -> Bool {
  84. if metadata.fileName != metadata.fileNameView && metadata.fileName.count == 32 && metadata.fileName.contains(".") == false {
  85. return true
  86. }
  87. return false
  88. }
  89. @objc func resizeImage(image: UIImage, toHeight: CGFloat) -> UIImage {
  90. return autoreleasepool { () -> UIImage in
  91. let toWidth = image.size.width * (toHeight/image.size.height)
  92. let targetSize = CGSize(width: toWidth, height: toHeight)
  93. let size = image.size
  94. let widthRatio = targetSize.width / size.width
  95. let heightRatio = targetSize.height / size.height
  96. // Orientation detection
  97. var newSize: CGSize
  98. if(widthRatio > heightRatio) {
  99. newSize = CGSize(width: size.width * heightRatio, height: size.height * heightRatio)
  100. } else {
  101. newSize = CGSize(width: size.width * widthRatio, height: size.height * widthRatio)
  102. }
  103. // Calculated rect
  104. let rect = CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height)
  105. // Resize
  106. UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0)
  107. image.draw(in: rect)
  108. let newImage = UIGraphicsGetImageFromCurrentImageContext()
  109. UIGraphicsEndImageContext()
  110. return newImage!
  111. }
  112. }
  113. func cellBlurEffect(with frame: CGRect) -> UIView {
  114. let blurEffect = UIBlurEffect(style: .extraLight)
  115. let blurEffectView = UIVisualEffectView(effect: blurEffect)
  116. blurEffectView.frame = frame
  117. blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  118. blurEffectView.backgroundColor = NCBrandColor.sharedInstance.brandElement.withAlphaComponent(0.2)
  119. return blurEffectView
  120. }
  121. func setLayoutForView(key: String, layout: String, sort: String, ascending: Bool, groupBy: String, directoryOnTop: Bool, titleButton: String, itemForLine: Int) {
  122. let string = layout + "|" + sort + "|" + "\(ascending)" + "|" + groupBy + "|" + "\(directoryOnTop)" + "|" + titleButton + "|" + "\(itemForLine)"
  123. UICKeyChainStore.setString(string, forKey: key, service: k_serviceShareKeyChain)
  124. }
  125. func setLayoutForView(key: String, layout: String) {
  126. var sort: String
  127. var ascending: Bool
  128. var groupBy: String
  129. var directoryOnTop: Bool
  130. var titleButton: String
  131. var itemForLine: Int
  132. (_, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: k_layout_view_favorite)
  133. setLayoutForView(key: key, layout: layout, sort: sort, ascending: ascending, groupBy: groupBy, directoryOnTop: directoryOnTop, titleButton: titleButton, itemForLine: itemForLine)
  134. }
  135. @objc func getLayoutForView(key: String) -> (String) {
  136. var layout: String
  137. (layout, _, _, _, _, _, _) = NCUtility.shared.getLayoutForView(key: key)
  138. return layout
  139. }
  140. @objc func getSortedForView(key: String) -> (String) {
  141. var sort: String
  142. (_, sort, _, _, _, _, _) = NCUtility.shared.getLayoutForView(key: key)
  143. return sort
  144. }
  145. @objc func getAscendingForView(key: String) -> (Bool) {
  146. var ascending: Bool
  147. (_, _, ascending, _, _, _, _) = NCUtility.shared.getLayoutForView(key: key)
  148. return ascending
  149. }
  150. @objc func getGroupByForView(key: String) -> (String) {
  151. var groupBy: String
  152. (_, _, _, groupBy, _, _, _) = NCUtility.shared.getLayoutForView(key: key)
  153. return groupBy
  154. }
  155. @objc func getDirectoryOnTopForView(key: String) -> (Bool) {
  156. var directoryOnTop: Bool
  157. (_, _, _, _, directoryOnTop, _, _) = NCUtility.shared.getLayoutForView(key: key)
  158. return directoryOnTop
  159. }
  160. @objc func getTitleButtonForView(key: String) -> (String) {
  161. var titleButton: String
  162. (_, _, _, _, _, titleButton, _) = NCUtility.shared.getLayoutForView(key: key)
  163. return titleButton
  164. }
  165. func getLayoutForView(key: String) -> (layout: String, sort: String, ascending: Bool, groupBy: String, directoryOnTop: Bool, titleButton: String, itemForLine: Int) {
  166. guard let string = UICKeyChainStore.string(forKey: key, service: k_serviceShareKeyChain) else {
  167. setLayoutForView(key: key, layout: k_layout_list, sort: "fileName", ascending: true, groupBy: "none", directoryOnTop: true, titleButton: "_sorted_by_name_a_z_", itemForLine: 3)
  168. return (k_layout_list, "fileName", true, "none", true, "_sorted_by_name_a_z_", 3)
  169. }
  170. let array = string.components(separatedBy: "|")
  171. if array.count == 7 {
  172. let sort = NSString(string: array[2])
  173. let directoryOnTop = NSString(string: array[4])
  174. let itemForLine = NSString(string: array[6])
  175. return (array[0], array[1], sort.boolValue, array[3], directoryOnTop.boolValue, array[5], Int(itemForLine.intValue))
  176. }
  177. setLayoutForView(key: key, layout: k_layout_list, sort: "fileName", ascending: true, groupBy: "none", directoryOnTop: true, titleButton: "_sorted_by_name_a_z_", itemForLine: 3)
  178. return (k_layout_list, "fileName", true, "none", true, "_sorted_by_name_a_z_", 3)
  179. }
  180. func convertSVGtoPNGWriteToUserData(svgUrlString: String, fileName: String?, width: CGFloat?, rewrite: Bool, account: String, closure: @escaping (String?) -> ()) {
  181. var fileNamePNG = ""
  182. guard let svgUrlString = svgUrlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {
  183. return closure(nil)
  184. }
  185. guard let iconURL = URL(string: svgUrlString) else {
  186. return closure(nil)
  187. }
  188. if fileName == nil {
  189. fileNamePNG = iconURL.deletingPathExtension().lastPathComponent + ".png"
  190. } else {
  191. fileNamePNG = fileName!
  192. }
  193. let imageNamePath = CCUtility.getDirectoryUserData() + "/" + fileNamePNG
  194. if !FileManager.default.fileExists(atPath: imageNamePath) || rewrite == true {
  195. NCCommunication.shared.downloadContent(serverUrl: iconURL.absoluteString) { (account, data, errorCode, errorMessage) in
  196. if errorCode == 0 && data != nil {
  197. if let image = UIImage.init(data: data!) {
  198. var newImage: UIImage = image
  199. if width != nil {
  200. let ratio = image.size.height / image.size.width
  201. let newSize = CGSize(width: width!, height: width! * ratio)
  202. let renderFormat = UIGraphicsImageRendererFormat.default()
  203. renderFormat.opaque = false
  204. let renderer = UIGraphicsImageRenderer(size: CGSize(width: newSize.width, height: newSize.height), format: renderFormat)
  205. newImage = renderer.image {
  206. (context) in
  207. image.draw(in: CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height))
  208. }
  209. }
  210. guard let pngImageData = newImage.pngData() else {
  211. return closure(nil)
  212. }
  213. CCUtility.write(pngImageData, fileNamePath: imageNamePath)
  214. return closure(imageNamePath)
  215. } else {
  216. guard let svgImage: SVGKImage = SVGKImage(data: data) else {
  217. return closure(nil)
  218. }
  219. if width != nil {
  220. let scale = svgImage.size.height / svgImage.size.width
  221. svgImage.size = CGSize(width: width!, height: width! * scale)
  222. }
  223. guard let image: UIImage = svgImage.uiImage else {
  224. return closure(nil)
  225. }
  226. guard let pngImageData = image.pngData() else {
  227. return closure(nil)
  228. }
  229. CCUtility.write(pngImageData, fileNamePath: imageNamePath)
  230. return closure(imageNamePath)
  231. }
  232. } else {
  233. return closure(nil)
  234. }
  235. }
  236. } else {
  237. return closure(imageNamePath)
  238. }
  239. }
  240. @objc func startActivityIndicator(view: UIView?, bottom: CGFloat = 0) {
  241. guard let view = view else { return }
  242. activityIndicator.color = NCBrandColor.sharedInstance.brandElement
  243. activityIndicator.hidesWhenStopped = true
  244. view.addSubview(activityIndicator)
  245. activityIndicator.translatesAutoresizingMaskIntoConstraints = false
  246. let horizontalConstraint = NSLayoutConstraint(item: activityIndicator, attribute: NSLayoutConstraint.Attribute.centerX, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.centerX, multiplier: 1, constant: 0)
  247. view.addConstraint(horizontalConstraint)
  248. var verticalConstant: CGFloat = 0
  249. if bottom > 0 {
  250. verticalConstant = (view.frame.size.height / 2) - bottom
  251. }
  252. let verticalConstraint = NSLayoutConstraint(item: activityIndicator, attribute: NSLayoutConstraint.Attribute.centerY, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.centerY, multiplier: 1, constant: verticalConstant)
  253. view.addConstraint(verticalConstraint)
  254. activityIndicator.startAnimating()
  255. }
  256. @objc func stopActivityIndicator() {
  257. activityIndicator.stopAnimating()
  258. activityIndicator.removeFromSuperview()
  259. }
  260. @objc func isSimulatorOrTestFlight() -> Bool {
  261. guard let path = Bundle.main.appStoreReceiptURL?.path else {
  262. return false
  263. }
  264. return path.contains("CoreSimulator") || path.contains("sandboxReceipt")
  265. }
  266. @objc func formatSecondsToString(_ seconds: TimeInterval) -> String {
  267. if seconds.isNaN {
  268. return "00:00:00"
  269. }
  270. let sec = Int(seconds.truncatingRemainder(dividingBy: 60))
  271. let min = Int(seconds.truncatingRemainder(dividingBy: 3600) / 60)
  272. let hour = Int(seconds / 3600)
  273. return String(format: "%02d:%02d:%02d", hour, min, sec)
  274. }
  275. @objc func blink(cell: AnyObject?) {
  276. DispatchQueue.main.async {
  277. if let cell = cell as? UITableViewCell {
  278. cell.backgroundColor = NCBrandColor.sharedInstance.brandElement.withAlphaComponent(0.3)
  279. UIView.animate(withDuration: 2) {
  280. cell.backgroundColor = .clear
  281. }
  282. } else if let cell = cell as? UICollectionViewCell {
  283. cell.backgroundColor = NCBrandColor.sharedInstance.brandElement.withAlphaComponent(0.3)
  284. UIView.animate(withDuration: 2) {
  285. cell.backgroundColor = .clear
  286. }
  287. }
  288. }
  289. }
  290. @objc func isRichDocument(_ metadata: tableMetadata) -> Bool {
  291. guard let mimeType = CCUtility.getMimeType(metadata.fileNameView) else {
  292. return false
  293. }
  294. guard let richdocumentsMimetypes = NCManageDatabase.sharedInstance.getCapabilitiesServerArray(account: metadata.account, elements: NCElementsJSON.shared.capabilitiesRichdocumentsMimetypes) else {
  295. return false
  296. }
  297. if richdocumentsMimetypes.count > 0 && mimeType.components(separatedBy: ".").count > 2 {
  298. let mimeTypeArray = mimeType.components(separatedBy: ".")
  299. let mimeType = mimeTypeArray[mimeTypeArray.count - 2] + "." + mimeTypeArray[mimeTypeArray.count - 1]
  300. for richdocumentMimetype: String in richdocumentsMimetypes {
  301. if richdocumentMimetype.contains(mimeType) {
  302. return true
  303. }
  304. }
  305. }
  306. return false
  307. }
  308. @objc func isDirectEditing(account: String, contentType: String) -> String? {
  309. var editor: String?
  310. guard let results = NCManageDatabase.sharedInstance.getDirectEditingEditors(account: account) else {
  311. return editor
  312. }
  313. for result: tableDirectEditingEditors in results {
  314. for mimetype in result.mimetypes {
  315. if mimetype == contentType {
  316. editor = result.editor
  317. }
  318. // HARDCODE
  319. // https://github.com/nextcloud/text/issues/913
  320. if mimetype == "text/markdown" && contentType == "text/x-markdown" {
  321. editor = result.editor
  322. }
  323. }
  324. for mimetype in result.optionalMimetypes {
  325. if mimetype == contentType {
  326. editor = result.editor
  327. }
  328. }
  329. }
  330. // HARDCODE
  331. if editor == "" {
  332. editor = k_editor_text
  333. }
  334. return editor
  335. }
  336. @objc func removeAllSettings() {
  337. URLCache.shared.memoryCapacity = 0
  338. URLCache.shared.diskCapacity = 0
  339. KTVHTTPCache.cacheDeleteAllCaches()
  340. NCManageDatabase.sharedInstance.clearDatabase(account: nil, removeAccount: true)
  341. CCUtility.removeGroupDirectoryProviderStorage()
  342. CCUtility.removeGroupLibraryDirectory()
  343. CCUtility.removeDocumentsDirectory()
  344. CCUtility.removeTemporaryDirectory()
  345. CCUtility.createDirectoryStandard()
  346. CCUtility.deleteAllChainStore()
  347. }
  348. #if !EXTENSION
  349. @objc func createAvatar(fileNameSource: String, fileNameSourceAvatar: String) -> UIImage? {
  350. guard let imageSource = UIImage(contentsOfFile: fileNameSource) else { return nil }
  351. let size = Int(k_avatar_size)
  352. UIGraphicsBeginImageContextWithOptions(CGSize(width: size, height: size), false, UIScreen.main.scale)
  353. imageSource.draw(in: CGRect(x: 0, y: 0, width: size, height: size))
  354. let image = UIGraphicsGetImageFromCurrentImageContext()
  355. UIGraphicsEndImageContext()
  356. UIGraphicsBeginImageContextWithOptions(CGSize(width: size, height: size), false, UIScreen.main.scale)
  357. let avatarImageView = CCAvatar.init(image: image, borderColor: .lightGray, borderWidth: Float(1 * UIScreen.main.scale))
  358. guard let context = UIGraphicsGetCurrentContext() else { return nil }
  359. avatarImageView?.layer.render(in: context)
  360. guard let imageAvatar = UIGraphicsGetImageFromCurrentImageContext() else { return nil }
  361. UIGraphicsEndImageContext()
  362. guard let data = imageAvatar.pngData() else {
  363. return nil
  364. }
  365. do {
  366. try data.write(to: NSURL(fileURLWithPath: fileNameSourceAvatar) as URL, options: .atomic)
  367. } catch { }
  368. return imageAvatar
  369. }
  370. #endif
  371. @objc func UIColorFromRGB(rgbValue: UInt32) -> UIColor {
  372. return UIColor(
  373. red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
  374. green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
  375. blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
  376. alpha: CGFloat(1.0)
  377. )
  378. }
  379. @objc func RGBFromUIColor(uicolorValue: UIColor) -> UInt32 {
  380. var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
  381. if uicolorValue.getRed(&red, green: &green, blue: &blue, alpha: &alpha) {
  382. var colorAsUInt : UInt32 = 0
  383. colorAsUInt += UInt32(red * 255.0) << 16 +
  384. UInt32(green * 255.0) << 8 +
  385. UInt32(blue * 255.0)
  386. return colorAsUInt
  387. }
  388. return 0
  389. }
  390. @objc func permissionsContainsString(_ metadataPermissions: String, permissions: String) -> Bool {
  391. for char in permissions {
  392. if metadataPermissions.contains(char) == false {
  393. return false
  394. }
  395. }
  396. return true
  397. }
  398. @objc func getCustomUserAgentOnlyOffice() -> String {
  399. let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString")!
  400. if UIDevice.current.userInterfaceIdiom == .pad {
  401. return "Mozilla/5.0 (iPad) Nextcloud-iOS/\(appVersion)"
  402. }else{
  403. return "Mozilla/5.0 (iPhone) Mobile Nextcloud-iOS/\(appVersion)"
  404. }
  405. }
  406. @objc func pdfThumbnail(url: URL, width: CGFloat = 240) -> UIImage? {
  407. guard let data = try? Data(contentsOf: url), let page = PDFDocument(data: data)?.page(at: 0) else {
  408. return nil
  409. }
  410. let pageSize = page.bounds(for: .mediaBox)
  411. let pdfScale = width / pageSize.width
  412. // Apply if you're displaying the thumbnail on screen
  413. let scale = UIScreen.main.scale * pdfScale
  414. let screenSize = CGSize(width: pageSize.width * scale, height: pageSize.height * scale)
  415. return page.thumbnail(of: screenSize, for: .mediaBox)
  416. }
  417. @objc func getMetadataConflict(account: String, serverUrl: String, fileName: String) -> tableMetadata? {
  418. // verify exists conflict
  419. let fileNameExtension = (fileName as NSString).pathExtension.lowercased()
  420. let fileNameWithoutExtension = (fileName as NSString).deletingPathExtension
  421. var fileNameConflict = fileName
  422. if fileNameExtension == "heic" && CCUtility.getFormatCompatibility() {
  423. fileNameConflict = fileNameWithoutExtension + ".jpg"
  424. }
  425. return NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameView == %@", account, serverUrl, fileNameConflict))
  426. }
  427. @objc func isQuickLookDisplayable(metadata: tableMetadata) -> Bool {
  428. return true
  429. }
  430. @objc func fromColor(color: UIColor) -> UIImage {
  431. let rect = CGRect(x: 0, y: 0, width: 1, height: 1)
  432. UIGraphicsBeginImageContext(rect.size)
  433. let context: CGContext? = UIGraphicsGetCurrentContext()
  434. context?.setFillColor(color.cgColor)
  435. context?.fill(rect)
  436. let image: UIImage? = UIGraphicsGetImageFromCurrentImageContext()
  437. UIGraphicsEndImageContext()
  438. return image ?? UIImage()
  439. }
  440. // Delete Asset on Photos album
  441. @objc func deleteAssetLocalIdentifiers(account: String, sessionSelector: String, completition: @escaping () -> ()) {
  442. if UIApplication.shared.applicationState != .active {
  443. completition()
  444. return
  445. }
  446. let metadatasSessionUpload = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND session CONTAINS[cd] %@", account, "upload"))
  447. if metadatasSessionUpload.count > 0 {
  448. completition()
  449. return
  450. }
  451. let localIdentifiers = NCManageDatabase.sharedInstance.getAssetLocalIdentifiersUploaded(account: account, sessionSelector: sessionSelector)
  452. if localIdentifiers.count == 0 {
  453. completition()
  454. return
  455. }
  456. let assets = PHAsset.fetchAssets(withLocalIdentifiers: localIdentifiers, options: nil)
  457. PHPhotoLibrary.shared().performChanges({
  458. PHAssetChangeRequest.deleteAssets(assets as NSFastEnumeration)
  459. }, completionHandler: { success, error in
  460. DispatchQueue.main.async {
  461. NCManageDatabase.sharedInstance.clearAssetLocalIdentifiers(localIdentifiers, account: account)
  462. completition()
  463. }
  464. })
  465. }
  466. @objc func ocIdToFileId(ocId: String?) -> String? {
  467. guard let ocId = ocId else { return nil }
  468. let items = ocId.components(separatedBy: "oc")
  469. if items.count < 2 { return nil }
  470. guard let intFileId = Int(items[0]) else { return nil }
  471. return String(intFileId)
  472. }
  473. }