2024-12-15 19:52:03 +00:00
|
|
|
import Foundation
|
|
|
|
|
2024-12-22 16:24:48 +00:00
|
|
|
public struct AuthToken: Hashable, Sendable {
|
2024-12-15 19:52:03 +00:00
|
|
|
public let id: Int
|
|
|
|
public let key: String
|
|
|
|
public let expireTime: Date
|
|
|
|
public let userId: Int
|
|
|
|
|
|
|
|
public init(id: Int, key: String, expireTime: Date, userId: Int) {
|
|
|
|
self.id = id
|
|
|
|
self.key = key
|
|
|
|
self.expireTime = expireTime
|
|
|
|
self.userId = userId
|
|
|
|
}
|
|
|
|
|
|
|
|
public var isExpired: Bool {
|
|
|
|
expireTime < Date()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-22 16:24:48 +00:00
|
|
|
public extension AuthToken {
|
|
|
|
public struct CodingData: Codable {
|
|
|
|
public struct Container: Codable {
|
2024-12-15 19:52:03 +00:00
|
|
|
let auth_token: AuthToken.CodingData
|
|
|
|
}
|
|
|
|
|
2024-12-22 16:24:48 +00:00
|
|
|
public let id: Int
|
|
|
|
public let key: String
|
|
|
|
public let expire_time: Int
|
|
|
|
public let user_id: Int
|
2024-12-15 19:52:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-22 16:24:48 +00:00
|
|
|
public extension AuthToken.CodingData {
|
|
|
|
public var decoded: AuthToken {
|
2024-12-15 19:52:03 +00:00
|
|
|
.init(
|
|
|
|
id: id,
|
|
|
|
key: key,
|
|
|
|
expireTime: Date(timeIntervalSince1970: TimeInterval(expire_time)),
|
|
|
|
userId: user_id
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2024-12-22 16:24:48 +00:00
|
|
|
|
|
|
|
public extension AuthToken {
|
|
|
|
public var encoded: AuthToken.CodingData {
|
|
|
|
.init(
|
|
|
|
id: id,
|
|
|
|
key: key,
|
|
|
|
expire_time: Int(expireTime.timeIntervalSince1970),
|
|
|
|
user_id: userId
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|