0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-18 02:21:47 -05:00

🐛 Fixed OpenSea NFT OEmbeds (#15372)

refs https://github.com/TryGhost/Team/issues/1879

OpenSea updated their URL format for NFTs after adding support for Solana
which broke our regex, this updates to support the new format.
This commit is contained in:
Fabien 'egg' O'Carroll 2022-09-06 11:29:35 -04:00 committed by GitHub
parent da1997d96e
commit f7a58ecafc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View file

@ -3,7 +3,7 @@
* @typedef {import('./oembed').IExternalRequest} IExternalRequest
*/
const OPENSEA_PATH_REGEX = /^\/assets\/(0x[a-f0-9]+)\/(\d+)/;
const OPENSEA_ETH_PATH_REGEX = /^\/assets\/ethereum\/(0x[a-f0-9]+)\/(\d+)/;
/**
* @implements ICustomProvider
@ -11,6 +11,8 @@ const OPENSEA_PATH_REGEX = /^\/assets\/(0x[a-f0-9]+)\/(\d+)/;
class NFTOEmbedProvider {
/**
* @param {object} dependencies
* @param {object} dependencies.config
* @param {string} [dependencies.config.apiKey] - An OpenSea API key
*/
constructor(dependencies) {
this.dependencies = dependencies;
@ -21,7 +23,7 @@ class NFTOEmbedProvider {
* @returns {Promise<boolean>}
*/
async canSupportRequest(url) {
return url.host === 'opensea.io' && OPENSEA_PATH_REGEX.test(url.pathname);
return url.host === 'opensea.io' && OPENSEA_ETH_PATH_REGEX.test(url.pathname);
}
/**
@ -31,7 +33,7 @@ class NFTOEmbedProvider {
* @returns {Promise<object>}
*/
async getOEmbedData(url, externalRequest) {
const [match, transaction, asset] = url.pathname.match(OPENSEA_PATH_REGEX);
const [match, transaction, asset] = url.pathname.match(OPENSEA_ETH_PATH_REGEX);
if (!match) {
return null;
}

View file

@ -0,0 +1,20 @@
const assert = require('assert');
const NFTOembedProvider = require('../../../../core/server/services/nft-oembed');
describe('NFTOEmbedProvider', function () {
it('Can support requests for OpenSea Ethereum NTFs', async function () {
const provider = new NFTOembedProvider({
config: {
apiKey: 'fake-api-key'
}
});
const ethereumNFTURL = new URL(
'https://opensea.io/assets/ethereum/0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb/9998'
);
const supportsRequest = await provider.canSupportRequest(ethereumNFTURL);
assert(supportsRequest, 'Should support ethereum NFT URL');
});
});