Pixelfed workaround.

This commit is contained in:
Marcin Czachursk 2023-02-18 15:46:32 +01:00
parent 7342c9f231
commit 94ee40ba44
2 changed files with 30 additions and 3 deletions

View File

@ -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
}
}
}
}

View File

@ -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;