IMImagemeter.swift 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. }
  37. struct capture_timestamp: Codable {
  38. let year: Int
  39. let month: Int
  40. let day: Int
  41. let hour: Int
  42. let minutes: Int
  43. let seconds: Int
  44. }
  45. struct image: Codable {
  46. let title: String
  47. let filename: String
  48. let annotated_image_filename: String
  49. let rotation:Int
  50. }
  51. struct elements: Codable {
  52. let id: Int
  53. let class_: String
  54. let center: [coordinates]
  55. let width: Int
  56. let arrows: [end_pt]
  57. let text: String
  58. let audio_recording: [audio_recording]
  59. }
  60. let version: Int
  61. let capture_timestamp: capture_timestamp
  62. let image: image
  63. let id: String
  64. let last_modification: Int
  65. let elements: [elements]
  66. }
  67. @objc static let sharedInstance: IMImagemeterCodable = {
  68. let instance = IMImagemeterCodable()
  69. return instance
  70. }()
  71. func decoderAnnotetion(_ annotation: Data) -> imagemeterAnnotation? {
  72. let jsonDecoder = JSONDecoder.init()
  73. do {
  74. let decode = try jsonDecoder.decode(imagemeterAnnotation.self, from: annotation)
  75. return decode
  76. } catch let error {
  77. print("Serious internal error in decoding metadata ("+error.localizedDescription+")")
  78. return nil
  79. }
  80. }
  81. }