Files
Morgan Pretty b11d8bc394 Started working on new reupload logic for user display pics
• Started working on the updated logic for the ReuploadUserDisplayPictureJob
• Pulled across a few changes from the refactored networking
• Pulled across the profile_updated changes from the animated profile pictures PR
2025-09-24 15:29:28 +10:00

42 lines
1.5 KiB
Swift

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
import Foundation
public struct FileUploadResponse: Codable {
public let id: String
public let uploaded: TimeInterval?
public let expires: TimeInterval?
public init(id: String, uploaded: TimeInterval?, expires: TimeInterval?) {
self.id = id
self.uploaded = uploaded
self.expires = expires
}
}
// MARK: - Codable
extension FileUploadResponse {
public init(from decoder: Decoder) throws {
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
// Note: SOGS returns an 'int' value but we want to avoid handling both cases so parse
// that and convert the value to a string so we can be consistent (SOGS is able to handle
// an array of Strings for the `files` param when posting a message just fine)
if let intValue: Int64 = try? container.decode(Int64.self, forKey: .id) {
self = FileUploadResponse(
id: "\(intValue)",
uploaded: try container.decodeIfPresent(TimeInterval.self, forKey: .uploaded),
expires: try container.decodeIfPresent(TimeInterval.self, forKey: .expires)
)
return
}
self = FileUploadResponse(
id: try container.decode(String.self, forKey: .id),
uploaded: try container.decodeIfPresent(TimeInterval.self, forKey: .uploaded),
expires: try container.decodeIfPresent(TimeInterval.self, forKey: .expires)
)
}
}