Refactor token media-type API to be token-scoped and safer#3190
Merged
Refactor token media-type API to be token-scoped and safer#3190
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description and Related Issue(s)
This pull request refactors the media-type API endpoint to be token-instance–scoped and backed by on-chain metadata, reducing the risk of arbitrary URL request forgery and tightening how we fetch and classify NFT media. It also hardens some node API endpoints (CSRF and Prometheus metrics) to only respond when explicitly enabled and improves metadata/analytics mappings for the new media-type route.
Proposed Changes
Media-type API refactor
/api/media-typeendpoint that accepted arbitraryurlquery parameters./api/tokens/[hash]/instances/[id]/media-typewhich:general:token_instanceand derives the media URL fromanimation_urlorimage_url.fieldparameter (animation_urlorimage_url) and returns a safe fallback when data is missing.HEADrequest against the resolved media URL with anAbortController-based timeout and Prometheus timing viametrics.apiRequestDuration.video,image,html, orundefinedbased on thecontent-typeheader.ui/shared/nft/useNftMediaInfoandNftMediaPlaywright tests to use the new token-scoped media-type route and theTokenInstance.tokenmetadata (address hash and id) when building media-type URLs.TokenInstanceintypes/api/tokenwith atoken: TokenInfofield so the UI can construct the scoped media-type requests.Metadata and analytics updates
lib/metadata/getPageOgType,lib/metadata/templates/title, andlib/metadata/templates/descriptionto use/api/tokens/[hash]/instances/[id]/media-typeinstead of/api/media-typefor OG/meta templates.lib/mixpanel/getPageTypeto track the new token-instance media-type endpoint as “Node API: Token instance media type”.nextjs/nextjs-routes.d.tsto remove the old static/api/media-typeroute and add the dynamic/api/tokens/[hash]/instances/[id]/media-typeroute type.Node API hardening
/api/csrfto return404when proxying is not needed (isNeedProxy()is false), instead of always forwarding./api/metricsto return404whenPROMETHEUS_METRICS_ENABLEDis nottrue, only exposing metrics when explicitly enabled.Environment variables
docs/ENVS.mdremains unchanged.Breaking or Incompatible Changes
/api/media-typeendpoint has been removed; any consumers relying on/node-api/media-type?url=...must migrate to/node-api/tokens/[hash]/instances/[id]/media-type?field=animation_url|image_url, wherehashandidcorrespond to the token instance and the field selects which media URL to inspect.Additional Information
NftMediahave been updated to reflect the new API shape, including realistic token address hashes and IDs wired through theTokenInstancefixture data.Checklist for PR author