Properly JSON encode image ALT fix #1492

This commit is contained in:
Thomas Ricouard 2023-07-17 19:35:16 +02:00
parent c0b34d352b
commit 9ed785db0e
2 changed files with 19 additions and 8 deletions

View file

@ -2,7 +2,7 @@ import Foundation
public enum Media: Endpoint {
case medias
case media(id: String, description: String?)
case media(id: String, json: MediaDescriptionData)
public func path() -> String {
switch self {
@ -14,14 +14,25 @@ public enum Media: Endpoint {
}
public func queryItems() -> [URLQueryItem]? {
return nil
}
public var jsonValue: Encodable? {
switch self {
case let .media(_, description):
if let description {
return [.init(name: "description", value: description)]
}
return nil
case let .media(_, json):
return json
default:
return nil
}
}
}
public struct MediaDescriptionData: Encodable, Sendable {
public let description: String?
public init(description: String?) {
self.description = description
}
}

View file

@ -674,7 +674,7 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
}
do {
let newAttachement: MediaAttachment = try await client.get(endpoint: Media.media(id: mediaAttachement.id,
description: nil))
json: .init(description: nil)))
if newAttachement.url != nil {
let oldContainer = mediasImages[index]
mediasImages[index] = .init(image: oldContainer.image,
@ -695,7 +695,7 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
if let index = indexOf(container: container) {
do {
let media: MediaAttachment = try await client.put(endpoint: Media.media(id: attachment.id,
description: description))
json: .init(description: description)))
mediasImages[index] = .init(image: nil,
movieTransferable: nil,
gifTransferable: nil,