NCUtility.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  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, serverUrl: 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. let key = key + serverUrl
  124. UICKeyChainStore.setString(string, forKey: key, service: k_serviceShareKeyChain)
  125. }
  126. func setLayoutForView(key: String, serverUrl: String, layout: String) {
  127. var sort: String
  128. var ascending: Bool
  129. var groupBy: String
  130. var directoryOnTop: Bool
  131. var titleButton: String
  132. var itemForLine: Int
  133. (_, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: k_layout_view_favorite, serverUrl: serverUrl)
  134. setLayoutForView(key: key, serverUrl: serverUrl, layout: layout, sort: sort, ascending: ascending, groupBy: groupBy, directoryOnTop: directoryOnTop, titleButton: titleButton, itemForLine: itemForLine)
  135. }
  136. @objc func getLayoutForView(key: String, serverUrl: String) -> (String) {
  137. var layout: String
  138. (layout, _, _, _, _, _, _) = NCUtility.shared.getLayoutForView(key: key, serverUrl: serverUrl)
  139. return layout
  140. }
  141. @objc func getSortedForView(key: String, serverUrl: String) -> (String) {
  142. var sort: String
  143. (_, sort, _, _, _, _, _) = NCUtility.shared.getLayoutForView(key: key, serverUrl: serverUrl)
  144. return sort
  145. }
  146. @objc func getAscendingForView(key: String, serverUrl: String) -> (Bool) {
  147. var ascending: Bool
  148. (_, _, ascending, _, _, _, _) = NCUtility.shared.getLayoutForView(key: key, serverUrl: serverUrl)
  149. return ascending
  150. }
  151. func getLayoutForView(key: String, serverUrl: String) -> (layout: String, sort: String, ascending: Bool, groupBy: String, directoryOnTop: Bool, titleButton: String, itemForLine: Int) {
  152. let key = key + serverUrl
  153. guard let string = UICKeyChainStore.string(forKey: key, service: k_serviceShareKeyChain) else {
  154. setLayoutForView(key: key, serverUrl: serverUrl, layout: k_layout_list, sort: "fileName", ascending: true, groupBy: "none", directoryOnTop: true, titleButton: "_sorted_by_name_a_z_", itemForLine: 3)
  155. return (k_layout_list, "fileName", true, "none", true, "_sorted_by_name_a_z_", 3)
  156. }
  157. let array = string.components(separatedBy: "|")
  158. if array.count == 7 {
  159. let sort = NSString(string: array[2])
  160. let directoryOnTop = NSString(string: array[4])
  161. let itemForLine = NSString(string: array[6])
  162. return (array[0], array[1], sort.boolValue, array[3], directoryOnTop.boolValue, array[5], Int(itemForLine.intValue))
  163. }
  164. setLayoutForView(key: key, serverUrl: serverUrl, layout: k_layout_list, sort: "fileName", ascending: true, groupBy: "none", directoryOnTop: true, titleButton: "_sorted_by_name_a_z_", itemForLine: 3)
  165. return (k_layout_list, "fileName", true, "none", true, "_sorted_by_name_a_z_", 3)
  166. }
  167. func convertSVGtoPNGWriteToUserData(svgUrlString: String, fileName: String?, width: CGFloat?, rewrite: Bool, account: String, closure: @escaping (String?) -> ()) {
  168. var fileNamePNG = ""
  169. guard let svgUrlString = svgUrlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {
  170. return closure(nil)
  171. }
  172. guard let iconURL = URL(string: svgUrlString) else {
  173. return closure(nil)
  174. }
  175. if fileName == nil {
  176. fileNamePNG = iconURL.deletingPathExtension().lastPathComponent + ".png"
  177. } else {
  178. fileNamePNG = fileName!
  179. }
  180. let imageNamePath = CCUtility.getDirectoryUserData() + "/" + fileNamePNG
  181. if !FileManager.default.fileExists(atPath: imageNamePath) || rewrite == true {
  182. NCCommunication.shared.downloadContent(serverUrl: iconURL.absoluteString) { (account, data, errorCode, errorMessage) in
  183. if errorCode == 0 && data != nil {
  184. if let image = UIImage.init(data: data!) {
  185. var newImage: UIImage = image
  186. if width != nil {
  187. let ratio = image.size.height / image.size.width
  188. let newSize = CGSize(width: width!, height: width! * ratio)
  189. let renderFormat = UIGraphicsImageRendererFormat.default()
  190. renderFormat.opaque = false
  191. let renderer = UIGraphicsImageRenderer(size: CGSize(width: newSize.width, height: newSize.height), format: renderFormat)
  192. newImage = renderer.image {
  193. (context) in
  194. image.draw(in: CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height))
  195. }
  196. }
  197. guard let pngImageData = newImage.pngData() else {
  198. return closure(nil)
  199. }
  200. CCUtility.write(pngImageData, fileNamePath: imageNamePath)
  201. return closure(imageNamePath)
  202. } else {
  203. guard let svgImage: SVGKImage = SVGKImage(data: data) else {
  204. return closure(nil)
  205. }
  206. if width != nil {
  207. let scale = svgImage.size.height / svgImage.size.width
  208. svgImage.size = CGSize(width: width!, height: width! * scale)
  209. }
  210. guard let image: UIImage = svgImage.uiImage else {
  211. return closure(nil)
  212. }
  213. guard let pngImageData = image.pngData() else {
  214. return closure(nil)
  215. }
  216. CCUtility.write(pngImageData, fileNamePath: imageNamePath)
  217. return closure(imageNamePath)
  218. }
  219. } else {
  220. return closure(nil)
  221. }
  222. }
  223. } else {
  224. return closure(imageNamePath)
  225. }
  226. }
  227. @objc func startActivityIndicator(view: UIView?, bottom: CGFloat = 0) {
  228. guard let view = view else { return }
  229. activityIndicator.color = NCBrandColor.sharedInstance.brandElement
  230. activityIndicator.hidesWhenStopped = true
  231. view.addSubview(activityIndicator)
  232. activityIndicator.translatesAutoresizingMaskIntoConstraints = false
  233. let horizontalConstraint = NSLayoutConstraint(item: activityIndicator, attribute: NSLayoutConstraint.Attribute.centerX, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.centerX, multiplier: 1, constant: 0)
  234. view.addConstraint(horizontalConstraint)
  235. var verticalConstant: CGFloat = 0
  236. if bottom > 0 {
  237. verticalConstant = (view.frame.size.height / 2) - bottom
  238. }
  239. let verticalConstraint = NSLayoutConstraint(item: activityIndicator, attribute: NSLayoutConstraint.Attribute.centerY, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.centerY, multiplier: 1, constant: verticalConstant)
  240. view.addConstraint(verticalConstraint)
  241. activityIndicator.startAnimating()
  242. }
  243. @objc func stopActivityIndicator() {
  244. activityIndicator.stopAnimating()
  245. activityIndicator.removeFromSuperview()
  246. }
  247. @objc func isSimulatorOrTestFlight() -> Bool {
  248. guard let path = Bundle.main.appStoreReceiptURL?.path else {
  249. return false
  250. }
  251. return path.contains("CoreSimulator") || path.contains("sandboxReceipt")
  252. }
  253. @objc func formatSecondsToString(_ seconds: TimeInterval) -> String {
  254. if seconds.isNaN {
  255. return "00:00:00"
  256. }
  257. let sec = Int(seconds.truncatingRemainder(dividingBy: 60))
  258. let min = Int(seconds.truncatingRemainder(dividingBy: 3600) / 60)
  259. let hour = Int(seconds / 3600)
  260. return String(format: "%02d:%02d:%02d", hour, min, sec)
  261. }
  262. @objc func blink(cell: AnyObject?) {
  263. DispatchQueue.main.async {
  264. if let cell = cell as? UITableViewCell {
  265. cell.backgroundColor = NCBrandColor.sharedInstance.brandElement.withAlphaComponent(0.3)
  266. UIView.animate(withDuration: 2) {
  267. cell.backgroundColor = .clear
  268. }
  269. } else if let cell = cell as? UICollectionViewCell {
  270. cell.backgroundColor = NCBrandColor.sharedInstance.brandElement.withAlphaComponent(0.3)
  271. UIView.animate(withDuration: 2) {
  272. cell.backgroundColor = .clear
  273. }
  274. }
  275. }
  276. }
  277. @objc func isRichDocument(_ metadata: tableMetadata) -> Bool {
  278. guard let mimeType = CCUtility.getMimeType(metadata.fileNameView) else {
  279. return false
  280. }
  281. guard let richdocumentsMimetypes = NCManageDatabase.sharedInstance.getCapabilitiesServerArray(account: metadata.account, elements: NCElementsJSON.shared.capabilitiesRichdocumentsMimetypes) else {
  282. return false
  283. }
  284. if richdocumentsMimetypes.count > 0 && mimeType.components(separatedBy: ".").count > 2 {
  285. let mimeTypeArray = mimeType.components(separatedBy: ".")
  286. let mimeType = mimeTypeArray[mimeTypeArray.count - 2] + "." + mimeTypeArray[mimeTypeArray.count - 1]
  287. for richdocumentMimetype: String in richdocumentsMimetypes {
  288. if richdocumentMimetype.contains(mimeType) {
  289. return true
  290. }
  291. }
  292. }
  293. return false
  294. }
  295. @objc func isDirectEditing(account: String, contentType: String) -> String? {
  296. var editor: String?
  297. guard let results = NCManageDatabase.sharedInstance.getDirectEditingEditors(account: account) else {
  298. return editor
  299. }
  300. for result: tableDirectEditingEditors in results {
  301. for mimetype in result.mimetypes {
  302. if mimetype == contentType {
  303. editor = result.editor
  304. }
  305. // HARDCODE
  306. // https://github.com/nextcloud/text/issues/913
  307. if mimetype == "text/markdown" && contentType == "text/x-markdown" {
  308. editor = result.editor
  309. }
  310. }
  311. for mimetype in result.optionalMimetypes {
  312. if mimetype == contentType {
  313. editor = result.editor
  314. }
  315. }
  316. }
  317. // HARDCODE
  318. if editor == "" {
  319. editor = k_editor_text
  320. }
  321. return editor
  322. }
  323. @objc func removeAllSettings() {
  324. URLCache.shared.memoryCapacity = 0
  325. URLCache.shared.diskCapacity = 0
  326. KTVHTTPCache.cacheDeleteAllCaches()
  327. NCManageDatabase.sharedInstance.clearDatabase(account: nil, removeAccount: true)
  328. CCUtility.removeGroupDirectoryProviderStorage()
  329. CCUtility.removeGroupLibraryDirectory()
  330. CCUtility.removeDocumentsDirectory()
  331. CCUtility.removeTemporaryDirectory()
  332. CCUtility.createDirectoryStandard()
  333. CCUtility.deleteAllChainStore()
  334. }
  335. #if !EXTENSION
  336. @objc func createAvatar(fileNameSource: String, fileNameSourceAvatar: String) -> UIImage? {
  337. guard let imageSource = UIImage(contentsOfFile: fileNameSource) else { return nil }
  338. let size = Int(k_avatar_size)
  339. UIGraphicsBeginImageContextWithOptions(CGSize(width: size, height: size), false, UIScreen.main.scale)
  340. imageSource.draw(in: CGRect(x: 0, y: 0, width: size, height: size))
  341. let image = UIGraphicsGetImageFromCurrentImageContext()
  342. UIGraphicsEndImageContext()
  343. UIGraphicsBeginImageContextWithOptions(CGSize(width: size, height: size), false, UIScreen.main.scale)
  344. let avatarImageView = CCAvatar.init(image: image, borderColor: .lightGray, borderWidth: Float(1 * UIScreen.main.scale))
  345. guard let context = UIGraphicsGetCurrentContext() else { return nil }
  346. avatarImageView?.layer.render(in: context)
  347. guard let imageAvatar = UIGraphicsGetImageFromCurrentImageContext() else { return nil }
  348. UIGraphicsEndImageContext()
  349. guard let data = imageAvatar.pngData() else {
  350. return nil
  351. }
  352. do {
  353. try data.write(to: NSURL(fileURLWithPath: fileNameSourceAvatar) as URL, options: .atomic)
  354. } catch { }
  355. return imageAvatar
  356. }
  357. #endif
  358. @objc func UIColorFromRGB(rgbValue: UInt32) -> UIColor {
  359. return UIColor(
  360. red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
  361. green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
  362. blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
  363. alpha: CGFloat(1.0)
  364. )
  365. }
  366. @objc func RGBFromUIColor(uicolorValue: UIColor) -> UInt32 {
  367. var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
  368. if uicolorValue.getRed(&red, green: &green, blue: &blue, alpha: &alpha) {
  369. var colorAsUInt : UInt32 = 0
  370. colorAsUInt += UInt32(red * 255.0) << 16 +
  371. UInt32(green * 255.0) << 8 +
  372. UInt32(blue * 255.0)
  373. return colorAsUInt
  374. }
  375. return 0
  376. }
  377. @objc func permissionsContainsString(_ metadataPermissions: String, permissions: String) -> Bool {
  378. for char in permissions {
  379. if metadataPermissions.contains(char) == false {
  380. return false
  381. }
  382. }
  383. return true
  384. }
  385. @objc func getCustomUserAgentOnlyOffice() -> String {
  386. let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString")!
  387. if UIDevice.current.userInterfaceIdiom == .pad {
  388. return "Mozilla/5.0 (iPad) Nextcloud-iOS/\(appVersion)"
  389. }else{
  390. return "Mozilla/5.0 (iPhone) Mobile Nextcloud-iOS/\(appVersion)"
  391. }
  392. }
  393. @objc func pdfThumbnail(url: URL, width: CGFloat = 240) -> UIImage? {
  394. guard let data = try? Data(contentsOf: url), let page = PDFDocument(data: data)?.page(at: 0) else {
  395. return nil
  396. }
  397. let pageSize = page.bounds(for: .mediaBox)
  398. let pdfScale = width / pageSize.width
  399. // Apply if you're displaying the thumbnail on screen
  400. let scale = UIScreen.main.scale * pdfScale
  401. let screenSize = CGSize(width: pageSize.width * scale, height: pageSize.height * scale)
  402. return page.thumbnail(of: screenSize, for: .mediaBox)
  403. }
  404. @objc func getMetadataConflict(account: String, serverUrl: String, fileName: String) -> tableMetadata? {
  405. // verify exists conflict
  406. let fileNameExtension = (fileName as NSString).pathExtension.lowercased()
  407. let fileNameWithoutExtension = (fileName as NSString).deletingPathExtension
  408. var fileNameConflict = fileName
  409. if fileNameExtension == "heic" && CCUtility.getFormatCompatibility() {
  410. fileNameConflict = fileNameWithoutExtension + ".jpg"
  411. }
  412. return NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameView == %@", account, serverUrl, fileNameConflict))
  413. }
  414. @objc func isQuickLookDisplayable(metadata: tableMetadata) -> Bool {
  415. return true
  416. }
  417. @objc func fromColor(color: UIColor) -> UIImage {
  418. let rect = CGRect(x: 0, y: 0, width: 1, height: 1)
  419. UIGraphicsBeginImageContext(rect.size)
  420. let context: CGContext? = UIGraphicsGetCurrentContext()
  421. context?.setFillColor(color.cgColor)
  422. context?.fill(rect)
  423. let image: UIImage? = UIGraphicsGetImageFromCurrentImageContext()
  424. UIGraphicsEndImageContext()
  425. return image ?? UIImage()
  426. }
  427. // Delete Asset on Photos album
  428. @objc func deleteAssetLocalIdentifiers(account: String, sessionSelector: String, completition: @escaping () -> ()) {
  429. if UIApplication.shared.applicationState != .active {
  430. completition()
  431. return
  432. }
  433. let metadatasSessionUpload = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND session CONTAINS[cd] %@", account, "upload"))
  434. if metadatasSessionUpload.count > 0 {
  435. completition()
  436. return
  437. }
  438. let localIdentifiers = NCManageDatabase.sharedInstance.getAssetLocalIdentifiersUploaded(account: account, sessionSelector: sessionSelector)
  439. if localIdentifiers.count == 0 {
  440. completition()
  441. return
  442. }
  443. let assets = PHAsset.fetchAssets(withLocalIdentifiers: localIdentifiers, options: nil)
  444. PHPhotoLibrary.shared().performChanges({
  445. PHAssetChangeRequest.deleteAssets(assets as NSFastEnumeration)
  446. }, completionHandler: { success, error in
  447. DispatchQueue.main.async {
  448. NCManageDatabase.sharedInstance.clearAssetLocalIdentifiers(localIdentifiers, account: account)
  449. completition()
  450. }
  451. })
  452. }
  453. @objc func ocIdToFileId(ocId: String?) -> String? {
  454. guard let ocId = ocId else { return nil }
  455. let items = ocId.components(separatedBy: "oc")
  456. if items.count < 2 { return nil }
  457. guard let intFileId = Int(items[0]) else { return nil }
  458. return String(intFileId)
  459. }
  460. }