mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.0 KiB
Swift
36 lines
1.0 KiB
Swift
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import Foundation
|
|
|
|
struct LegacyFileDownloadResponse: Codable {
|
|
enum CodingKeys: String, CodingKey {
|
|
case base64EncodedData = "result"
|
|
}
|
|
|
|
let data: Data
|
|
|
|
public func encode(to encoder: Encoder) throws {
|
|
var container: KeyedEncodingContainer<CodingKeys> = encoder.container(keyedBy: CodingKeys.self)
|
|
|
|
try container.encode(data.base64EncodedString(), forKey: .base64EncodedData)
|
|
}
|
|
}
|
|
|
|
// MARK: - Decoder
|
|
|
|
extension LegacyFileDownloadResponse {
|
|
init(from decoder: Decoder) throws {
|
|
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
|
let base64EncodedData: String = try container.decode(String.self, forKey: .base64EncodedData)
|
|
|
|
guard let data = Data(base64Encoded: base64EncodedData) else {
|
|
throw FileServerAPIV2.Error.parsingFailed
|
|
}
|
|
|
|
self = LegacyFileDownloadResponse(
|
|
data: data
|
|
)
|
|
}
|
|
}
|