IMImagemeter.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //
  2. // IMImagemeter.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 22/03/2019.
  6. // Copyright © 2019 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. class IMImagemeterCodable: NSObject {
  25. struct imagemeterAnnotation: Codable {
  26. struct coordinates: Codable {
  27. let x: Int
  28. let y: Int
  29. }
  30. struct end_pt: Codable {
  31. let coordinates: [coordinates]
  32. }
  33. struct audio_recording: Codable {
  34. let recording_filename: String
  35. let recording_duration_msecs: Int
  36. enum CodingKeys : String, CodingKey {
  37. case recording_filename = "recording-filename"
  38. case recording_duration_msecs = "recording-duration_msecs"
  39. }
  40. }
  41. struct capture_timestamp: Codable {
  42. let year: Int
  43. let month: Int
  44. let day: Int
  45. let hour: Int
  46. let minutes: Int
  47. let seconds: Int
  48. }
  49. struct image: Codable {
  50. let title: String
  51. let filename: String
  52. let annotated_image_filename: String
  53. let rotation:Int
  54. enum CodingKeys : String, CodingKey {
  55. case title
  56. case filename
  57. case annotated_image_filename = "annotated-image-filename"
  58. case rotation
  59. }
  60. }
  61. struct elements: Codable {
  62. let id: Int
  63. let class_: String
  64. // let center: coordinates
  65. // let width: Int
  66. // let arrows: [end_pt]
  67. // let text: String
  68. // let audio_recording: [audio_recording]
  69. enum CodingKeys : String, CodingKey {
  70. case id
  71. case class_ = "class"
  72. // case center
  73. // case width
  74. // case arrows
  75. // case text
  76. // case audio_recording = "audio-recording"
  77. }
  78. }
  79. struct thumbnails: Codable {
  80. let filename: String
  81. let width: Int
  82. let height: Int
  83. }
  84. let is_example_image: Bool
  85. let version: Int
  86. let capture_timestamp: capture_timestamp
  87. let image: image
  88. let elements: [elements]
  89. let id: String
  90. let thumbnails: [thumbnails]
  91. let last_modification: Int
  92. enum CodingKeys : String, CodingKey {
  93. case is_example_image = "is-example-image"
  94. case version
  95. case capture_timestamp = "capture-timestamp"
  96. case image
  97. case elements
  98. case id
  99. case thumbnails
  100. case last_modification = "last-modification"
  101. }
  102. }
  103. @objc static let sharedInstance: IMImagemeterCodable = {
  104. let instance = IMImagemeterCodable()
  105. return instance
  106. }()
  107. func decoderAnnotetion(_ annotation: Data) -> imagemeterAnnotation? {
  108. let jsonDecoder = JSONDecoder.init()
  109. do {
  110. let decode = try jsonDecoder.decode(imagemeterAnnotation.self, from: annotation)
  111. return decode
  112. } catch let error {
  113. print("Serious internal error in decoding metadata ("+error.localizedDescription+")")
  114. return nil
  115. }
  116. }
  117. }