-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Core Data: Update Attachment type to more accurately reflect fields in media API responses #73223
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
Core Data: Update Attachment type to more accurately reflect fields in media API responses #73223
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Flaky tests detected in 5a80c7f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/19319945010
|
ramonjd
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tellthemachines
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes LGTM!
| width?: number; | ||
| height?: number; | ||
| file?: string; | ||
| filesize?: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't file and filesize always exist? Or are there circumstances in which we don't have access to them through the API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As strange as it might seem, MediaDetails can actually be an empty object! The REST API gets the attachment metadata (which can be filtered) and if it's empty it'll return an empty object:
In practice and normal usage (and in the included fixtures) filesize is always present, but file isn't always. This is what Claude tells me across these fixtures:
Fixture Results:
| Fixture | file | filesize |
|---|---|---|
| Image | ✅ Present | ✅ Present |
| Zip | ❌ Missing | ✅ Present |
| Audio | ❌ Missing | ✅ Present |
| Video | ❌ Missing | ✅ Present |
Because we're technically displaying what's in the metadata in this interface (and an empty object is a valid response), I'm leaning toward keeping these optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! If they don't always exist they should be optional.
| date?: string; | ||
| comment?: string; | ||
| band?: string; | ||
| year?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that these metadata are specific to audio! Some of them would be useful for video too. Very much not a problem for this PR though 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, totally! I believe most of these are from id3 tags from my quick skim of wordpress-develop
| }; | ||
| } | ||
| interface ImageMeta { | ||
| aperture: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have thought aperture would be optional but apparently when we don't have the info we just set it to "0" 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a few things like that!
|
Thanks for reviewing, folks! I'll merge this in, but happy to do any follow-ups if any of these types look off. I believe this update will help us quite a bit when it comes to building out media library interfaces and fields using all these properties. |


What?
Part of: #72612
Update the Attachment type to more accurately reflect the properties found in actual API responses.
A Claude-generated overview of what's changed
MediaDetails interface
width?,height?,file?,filesize?,image_meta?)caption field (add support for handling rich text)
RenderedText< C >instead of a plain stringrawandrenderedpropertiesmeta field
Record< string, unknown >toRecord< string, unknown > | []post field (previously this expected the media item to always be attached to a post)
null(number | null) instead of justnumberNew fields (these are always present in API responses)
featured_mediaclass_list_linksThese changes broaden the attachment type definition to properly support all (I hope!) attachment media types (images, audio, video, files) and their specific metadata properties.
Why?
While hacking around on support for media as part of dedicated media fields over in #73071, I kept running into issues where properties weren't typed in a way that actually matched the API responses I was working with.
This PR seeks to better match the typing to actual responses, which should (hopefully) make it easier to work with attachment types in TypeScript.
How?
Testing Instructions
captionand I noticed our types didn't allow for rich text to be handled, and then the rest of this PR came about because I thought if I'm going to update one property, I'd better check the whole thing against real API responses.