NCNetworking+LivePhoto.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // NCNetworking+LivePhoto.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 07/02/24.
  6. // Copyright © 2024 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 UIKit
  24. import NextcloudKit
  25. import Alamofire
  26. import Queuer
  27. extension NCNetworking {
  28. func uploadLivePhoto(metadata: tableMetadata, userInfo aUserInfo: [AnyHashable: Any]) {
  29. database.realmRefresh()
  30. guard let metadata1 = database.getMetadata(predicate: NSPredicate(format: "account == %@ AND urlBase == %@ AND path == %@ AND fileName == %@",
  31. metadata.account,
  32. metadata.urlBase,
  33. metadata.path,
  34. metadata.livePhotoFile)) else {
  35. metadata.livePhotoFile = ""
  36. self.database.addMetadata(metadata)
  37. return NotificationCenter.default.postOnMainThread(name: self.global.notificationCenterUploadedLivePhoto,
  38. object: nil,
  39. userInfo: aUserInfo,
  40. second: 0.5)
  41. }
  42. if metadata1.status != self.global.metadataStatusNormal {
  43. return NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Upload set LivePhoto for files (NO Status Normal) " + (metadata1.fileName as NSString).deletingPathExtension)
  44. }
  45. Task {
  46. /// METADATA
  47. let serverUrlfileNamePath = metadata.urlBase + metadata.path + metadata.fileName
  48. var livePhotoFile = metadata1.fileId
  49. let resultsMetadata = await setLivephoto(serverUrlfileNamePath: serverUrlfileNamePath, livePhotoFile: livePhotoFile, account: metadata.account)
  50. if resultsMetadata.error == .success {
  51. database.setMetadataLivePhotoByServer(account: metadata.account, ocId: metadata.ocId, livePhotoFile: livePhotoFile)
  52. }
  53. /// METADATA 1
  54. let serverUrlfileNamePath1 = metadata1.urlBase + metadata1.path + metadata1.fileName
  55. livePhotoFile = metadata.fileId
  56. let resultsMetadata1 = await setLivephoto(serverUrlfileNamePath: serverUrlfileNamePath1, livePhotoFile: livePhotoFile, account: metadata1.account)
  57. if resultsMetadata1.error == .success {
  58. database.setMetadataLivePhotoByServer(account: metadata1.account, ocId: metadata1.ocId, livePhotoFile: livePhotoFile)
  59. }
  60. if resultsMetadata.error == .success, resultsMetadata1.error == .success {
  61. NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Upload set LivePhoto for files " + (metadata.fileName as NSString).deletingPathExtension)
  62. } else {
  63. NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Upload set LivePhoto with error \(resultsMetadata.error.errorCode) - \(resultsMetadata1.error.errorCode)")
  64. }
  65. NotificationCenter.default.postOnMainThread(name: self.global.notificationCenterUploadedLivePhoto,
  66. object: nil,
  67. userInfo: aUserInfo,
  68. second: 0.5)
  69. }
  70. }
  71. }