Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make some Embed "media" fields optional #1

Merged
merged 3 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ I prefer indentation with tabs for improved accessibility. But, I'd rather you u

By participating in this project you agree to abide by the [Contributor Code of Conduct](CODE_OF_CONDUCT.md).

[build status]: https://github.com/mattmassicotte/ATResolve/actions
[build status badge]: https://github.com/mattmassicotte/ATResolve/workflows/CI/badge.svg
[build status]: https://github.com/mattmassicotte/ATAT/actions
[build status badge]: https://github.com/mattmassicotte/ATAT/workflows/CI/badge.svg
[matrix]: https://matrix.to/#/%23chimehq%3Amatrix.org
[matrix badge]: https://img.shields.io/matrix/chimehq%3Amatrix.org?label=Matrix
[discord]: https://discord.gg/esFpX6sErJ
10 changes: 5 additions & 5 deletions Sources/ATAT/Embed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ extension Bsky.Embed {
public struct Images: Decodable, Hashable, Sendable {
public struct Image: Decodable, Hashable, Sendable {
public let alt: String
public let aspectRatio: AspectRatio
public let aspectRatio: AspectRatio?
public let image: Bsky.Blob
}

Expand All @@ -98,7 +98,7 @@ extension Bsky.Embed {
extension Bsky.Embed.Images {
public struct ViewImage: Decodable, Hashable, Sendable {
public let alt: String
public let aspectRatio: Bsky.Embed.AspectRatio
public let aspectRatio: Bsky.Embed.AspectRatio?
public let fullsize: String
public let thumb: String
}
Expand All @@ -110,7 +110,7 @@ extension Bsky.Embed.Images {

extension Bsky.Embed {
public struct Video: Decodable, Hashable, Sendable {
public let aspectRatio: Bsky.Embed.AspectRatio
public let aspectRatio: Bsky.Embed.AspectRatio?
public let video: Bsky.Blob
}
}
Expand All @@ -119,7 +119,7 @@ extension Bsky.Embed.Video {
public struct View: Decodable, Hashable, Sendable {
public let cid: ATProtoCID
public let playlist: String
public let thumbnail: String
public let aspectRatio: Bsky.Embed.AspectRatio
public let thumbnail: String?
public let aspectRatio: Bsky.Embed.AspectRatio?
}
}
17 changes: 10 additions & 7 deletions Tests/ATATTests/PostTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,21 @@ struct PostTests {

#expect(images.images.count == 1)
let image = try #require(images.images.first)
let imageAspectRatio = try #require(image.aspectRatio)

#expect(image.aspectRatio.height == 1500)
#expect(image.aspectRatio.width == 1999)
#expect(imageAspectRatio.height == 1500)
#expect(imageAspectRatio.width == 1999)
#expect(image.image.mimeType == "image/jpeg")
#expect(image.image.size == 922545)

guard case let .imagesView(imagesView) = post.embed else { fatalError() }

#expect(imagesView.images.count == 1)
let imageView = try #require(imagesView.images.first)

#expect(imageView.aspectRatio.height == 1500)
#expect(imageView.aspectRatio.width == 1999)
let imageViewAspectRatio = try #require(imageView.aspectRatio)

#expect(imageViewAspectRatio.height == 1500)
#expect(imageViewAspectRatio.width == 1999)
#expect(imageView.fullsize == "https://cdn.bsky.app/img/feed_fullsize/plain/did:plc:z7ja7uhcr5is6uqmnsjyn3k7/bafkreicjr5ezdgwv6z4zcxv2egqjmaox6ocplsrhvubmmfqyuh6dybhfma@jpeg")
}

Expand Down Expand Up @@ -176,10 +178,11 @@ struct PostTests {
#expect(embedVideo.video.mimeType == "video/mp4")

guard case let .embedVideoView(embedVideoView) = post.embed else { fatalError() }
let videoAspectRatio = try #require(embedVideoView.aspectRatio)

#expect(embedVideoView.playlist == "https://video.bsky.app/watch/did%3Aplc%3Al7mosai5i2u562b5qbosw6c7/bafkreic3uqlah5pnqzq4tx2r5cg6kyj2uziq4jn4uatuwdhvl33sx2qkgm/playlist.m3u8")
#expect(embedVideoView.thumbnail == "https://video.bsky.app/watch/did%3Aplc%3Al7mosai5i2u562b5qbosw6c7/bafkreic3uqlah5pnqzq4tx2r5cg6kyj2uziq4jn4uatuwdhvl33sx2qkgm/thumbnail.jpg")
#expect(embedVideoView.aspectRatio.height == 1920)
#expect(embedVideoView.aspectRatio.width == 1920)
#expect(videoAspectRatio.height == 1920)
#expect(videoAspectRatio.width == 1920)
}
}
Loading