From 94ee40ba4420e1ba6581f023118949f8648e20c0 Mon Sep 17 00:00:00 2001 From: Marcin Czachursk Date: Sat, 18 Feb 2023 15:46:32 +0100 Subject: [PATCH] Pixelfed workaround. --- .../MastodonKit/MastodonClient+Media.swift | 29 ++++++++++++++++++- Vernissage.xcodeproj/project.pbxproj | 4 +-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/MastodonKit/Sources/MastodonKit/MastodonClient+Media.swift b/MastodonKit/Sources/MastodonKit/MastodonClient+Media.swift index 7f81a6a..b9799d0 100644 --- a/MastodonKit/Sources/MastodonKit/MastodonClient+Media.swift +++ b/MastodonKit/Sources/MastodonKit/MastodonClient+Media.swift @@ -22,6 +22,33 @@ public extension MastodonClientAuthenticated { target: Mastodon.Media.update(id, description, focus), withBearerToken: token) - return try await downloadJson(UploadedAttachment.self, request: request) + let (data, response) = try await urlSession.data(for: request) + + // TODO: Pixelfed.social returns some list instead of single media! + // return try await downloadJson(UploadedAttachment.self, request: request) + + guard (response as? HTTPURLResponse)?.status?.responseType == .success else { + throw NetworkError.notSuccessResponse(response) + } + + do { + return try JSONDecoder().decode(UploadedAttachment.self, from: data) + } catch { + do { + let list = try JSONDecoder().decode([UploadedAttachment].self, from: data) + print("[Error] Instead of single item server retured list of others media attachments!") + + if let entity = list.first(where: { item in item.id == id }) { + return entity + } + + throw NetworkError.unknownError + } catch { + let json = String(data: data, encoding: .utf8)! + print(json) + + throw error + } + } } } diff --git a/Vernissage.xcodeproj/project.pbxproj b/Vernissage.xcodeproj/project.pbxproj index 4deea8b..35b5c18 100644 --- a/Vernissage.xcodeproj/project.pbxproj +++ b/Vernissage.xcodeproj/project.pbxproj @@ -967,7 +967,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 5; + CURRENT_PROJECT_VERSION = 6; DEVELOPMENT_ASSET_PATHS = "\"Vernissage/Preview Content\""; DEVELOPMENT_TEAM = B2U9FEKYP8; ENABLE_PREVIEWS = YES; @@ -1004,7 +1004,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 5; + CURRENT_PROJECT_VERSION = 6; DEVELOPMENT_ASSET_PATHS = "\"Vernissage/Preview Content\""; DEVELOPMENT_TEAM = B2U9FEKYP8; ENABLE_PREVIEWS = YES;