2020-08-30 23:33:11 +00:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
public struct Attachment: Codable, Hashable {
|
|
|
|
public enum AttachmentType: String, Codable, Hashable, Unknowable {
|
|
|
|
case image, video, gifv, audio, unknown
|
|
|
|
|
|
|
|
public static var unknownCase: Self { .unknown }
|
|
|
|
}
|
|
|
|
|
|
|
|
// swiftlint:disable nesting
|
|
|
|
public struct Meta: Codable, Hashable {
|
|
|
|
public struct Info: Codable, Hashable {
|
|
|
|
public let width: Int?
|
|
|
|
public let height: Int?
|
|
|
|
public let size: String?
|
|
|
|
public let aspect: Double?
|
|
|
|
public let frameRate: String?
|
|
|
|
public let duration: Double?
|
|
|
|
public let bitrate: Int?
|
|
|
|
}
|
|
|
|
|
|
|
|
public struct Focus: Codable, Hashable {
|
|
|
|
public let x: Double
|
|
|
|
public let y: Double
|
|
|
|
}
|
|
|
|
|
|
|
|
public let original: Info?
|
|
|
|
public let small: Info?
|
|
|
|
public let focus: Focus?
|
|
|
|
}
|
|
|
|
// swiftlint:enable nesting
|
|
|
|
|
2020-10-05 22:50:05 +00:00
|
|
|
public let id: Id
|
2020-08-30 23:33:11 +00:00
|
|
|
public let type: AttachmentType
|
|
|
|
public let url: URL
|
|
|
|
public let remoteUrl: URL?
|
2020-09-23 01:46:33 +00:00
|
|
|
public let previewUrl: URL?
|
2020-08-30 23:33:11 +00:00
|
|
|
public let textUrl: URL?
|
|
|
|
public let meta: Meta?
|
|
|
|
public let description: String?
|
|
|
|
}
|
2020-10-05 22:50:05 +00:00
|
|
|
|
|
|
|
public extension Attachment {
|
|
|
|
typealias Id = String
|
2021-01-03 01:22:17 +00:00
|
|
|
|
|
|
|
var aspectRatio: Double? {
|
|
|
|
if
|
|
|
|
let info = meta?.original,
|
|
|
|
let width = info.width,
|
|
|
|
let height = info.height,
|
|
|
|
width != 0,
|
|
|
|
height != 0 {
|
|
|
|
let aspectRatio = Double(width) / Double(height)
|
|
|
|
|
|
|
|
return aspectRatio.isNaN ? nil : aspectRatio
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-10-05 22:50:05 +00:00
|
|
|
}
|