2024-12-22 16:24:48 +00:00
|
|
|
import Foundation
|
|
|
|
|
2024-12-11 10:54:12 +00:00
|
|
|
public extension User {
|
2024-12-22 16:24:48 +00:00
|
|
|
struct Avatar: Hashable, Sendable {
|
2024-12-11 10:54:12 +00:00
|
|
|
public let colorHex: String
|
|
|
|
|
|
|
|
public let imageUrlPath: String?
|
|
|
|
|
2024-12-22 16:24:48 +00:00
|
|
|
public var imageUrl: URL? {
|
|
|
|
imageUrlPath.flatMap { URL(string: "https://avatars.devrant.com/\($0)") }
|
2024-12-11 10:54:12 +00:00
|
|
|
}
|
2024-12-11 16:00:16 +00:00
|
|
|
|
|
|
|
public init(colorHex: String, imageUrlPath: String?) {
|
|
|
|
self.colorHex = colorHex
|
|
|
|
self.imageUrlPath = imageUrlPath
|
|
|
|
}
|
2024-12-11 10:54:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension User.Avatar {
|
|
|
|
struct CodingData: Codable {
|
|
|
|
let b: String
|
|
|
|
let i: String?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension User.Avatar.CodingData {
|
|
|
|
var decoded: User.Avatar {
|
|
|
|
.init(
|
|
|
|
colorHex: b,
|
|
|
|
imageUrlPath: i
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|