feat: block dynamic link previews for blocked collections (#7344)
* feat: block link previews for blocked collections * update collection test * single invalid * move blocklist to its own const file * rename file to blocklist
This commit is contained in:
parent
43f4d0f1b0
commit
13f57d8d73
@ -2,6 +2,7 @@
|
|||||||
import { ImageResponse } from '@vercel/og'
|
import { ImageResponse } from '@vercel/og'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
|
import { blocklistedCollections } from '../../../../../src/nft/utils/blocklist'
|
||||||
import { WATERMARK_URL } from '../../../../constants'
|
import { WATERMARK_URL } from '../../../../constants'
|
||||||
import getAsset from '../../../../utils/getAsset'
|
import getAsset from '../../../../utils/getAsset'
|
||||||
import getFont from '../../../../utils/getFont'
|
import getFont from '../../../../utils/getFont'
|
||||||
@ -15,6 +16,10 @@ export const onRequest: PagesFunction = async ({ params, request }) => {
|
|||||||
const tokenId = index[1]?.toString()
|
const tokenId = index[1]?.toString()
|
||||||
const cacheUrl = origin + '/nfts/asset/' + collectionAddress + '/' + tokenId
|
const cacheUrl = origin + '/nfts/asset/' + collectionAddress + '/' + tokenId
|
||||||
|
|
||||||
|
if (blocklistedCollections.includes(collectionAddress)) {
|
||||||
|
return new Response('Collection unsupported.', { status: 404 })
|
||||||
|
}
|
||||||
|
|
||||||
const data = await getRequest(
|
const data = await getRequest(
|
||||||
cacheUrl,
|
cacheUrl,
|
||||||
() => getAsset(collectionAddress, tokenId, cacheUrl),
|
() => getAsset(collectionAddress, tokenId, cacheUrl),
|
||||||
|
@ -18,3 +18,12 @@ test.each(invalidAssetImageUrl)('invalidAssetImageUrl', async (url) => {
|
|||||||
const response = await fetch(new Request(url))
|
const response = await fetch(new Request(url))
|
||||||
expect(response.status).toBe(404)
|
expect(response.status).toBe(404)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const blockedAssetImageUrl = [
|
||||||
|
'http://127.0.0.1:3000/api/image/nfts/asset/0xd4d871419714b778ebec2e22c7c53572b573706e/276',
|
||||||
|
]
|
||||||
|
|
||||||
|
test.each(blockedAssetImageUrl)('blockedAssetImageUrl', async (url) => {
|
||||||
|
const response = await fetch(new Request(url))
|
||||||
|
expect(response.status).toBe(404)
|
||||||
|
})
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import { ImageResponse } from '@vercel/og'
|
import { ImageResponse } from '@vercel/og'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
|
import { blocklistedCollections } from '../../../../../src/nft/utils/blocklist'
|
||||||
import { CHECK_URL, WATERMARK_URL } from '../../../../constants'
|
import { CHECK_URL, WATERMARK_URL } from '../../../../constants'
|
||||||
import getCollection from '../../../../utils/getCollection'
|
import getCollection from '../../../../utils/getCollection'
|
||||||
import getColor from '../../../../utils/getColor'
|
import getColor from '../../../../utils/getColor'
|
||||||
@ -15,6 +16,10 @@ export const onRequest: PagesFunction = async ({ params, request }) => {
|
|||||||
const collectionAddress = index?.toString()
|
const collectionAddress = index?.toString()
|
||||||
const cacheUrl = origin + '/nfts/collection/' + collectionAddress
|
const cacheUrl = origin + '/nfts/collection/' + collectionAddress
|
||||||
|
|
||||||
|
if (blocklistedCollections.includes(collectionAddress)) {
|
||||||
|
return new Response('Collection unsupported.', { status: 404 })
|
||||||
|
}
|
||||||
|
|
||||||
const data = await getRequest(
|
const data = await getRequest(
|
||||||
cacheUrl,
|
cacheUrl,
|
||||||
() => getCollection(collectionAddress, cacheUrl),
|
() => getCollection(collectionAddress, cacheUrl),
|
||||||
|
@ -23,3 +23,12 @@ test.each(invalidCollectionImageUrls)('invalidAssetImageUrl', async (url) => {
|
|||||||
const response = await fetch(new Request(url))
|
const response = await fetch(new Request(url))
|
||||||
expect(response.status).toBeOneOf([404, 500])
|
expect(response.status).toBeOneOf([404, 500])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const blockedCollectionImageUrls = [
|
||||||
|
'http://127.0.0.1:3000/api/image/nfts/collection/0xd4d871419714b778ebec2e22c7c53572b573706e',
|
||||||
|
]
|
||||||
|
|
||||||
|
test.each(blockedCollectionImageUrls)('blockedCollectionImageUrl', async (url) => {
|
||||||
|
const response = await fetch(new Request(url))
|
||||||
|
expect(response.status).toBeOneOf([404, 500])
|
||||||
|
})
|
||||||
|
13
src/nft/utils/blocklist.ts
Normal file
13
src/nft/utils/blocklist.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
export const blocklistedCollections = [
|
||||||
|
'0xd5eeac01b0d1d929d6cffaaf78020af137277293',
|
||||||
|
'0x85c08fffa9510f87019efdcf986301873cbb10d6',
|
||||||
|
'0x32d7e58933fceea6b73a13f8e30605d80915b616',
|
||||||
|
'0x85c08fffa9510f87019efdcf986301873cbb10d6',
|
||||||
|
'0xd5eeac01b0d1d929d6cffaaf78020af137277293',
|
||||||
|
'0x88e49f9fd4cc3d30f2f46c652f59fb52c4874f23',
|
||||||
|
'0xabefbc9fd2f806065b4f3c237d4b59d9a97bcac7',
|
||||||
|
'0xd945f759d422ae30a6166838317b937de08380e3',
|
||||||
|
'0x8e52fb89b6311bd9ec36bd7cea9a0c311fd27a92',
|
||||||
|
'0x2079c2765462af6d78a9ccbddb6ff3c6d4ba2e24',
|
||||||
|
'0xd4d871419714b778ebec2e22c7c53572b573706e',
|
||||||
|
]
|
@ -22,17 +22,3 @@ export const isInSameSudoSwapPool = (assetA: GenieAsset, assetB: GenieAsset): bo
|
|||||||
export const isInSameMarketplaceCollection = (assetA: GenieAsset, assetB: GenieAsset): boolean => {
|
export const isInSameMarketplaceCollection = (assetA: GenieAsset, assetB: GenieAsset): boolean => {
|
||||||
return assetA.address === assetB.address && assetA.marketplace === assetB.marketplace
|
return assetA.address === assetB.address && assetA.marketplace === assetB.marketplace
|
||||||
}
|
}
|
||||||
|
|
||||||
export const blocklistedCollections = [
|
|
||||||
'0xd5eeac01b0d1d929d6cffaaf78020af137277293',
|
|
||||||
'0x85c08fffa9510f87019efdcf986301873cbb10d6',
|
|
||||||
'0x32d7e58933fceea6b73a13f8e30605d80915b616',
|
|
||||||
'0x85c08fffa9510f87019efdcf986301873cbb10d6',
|
|
||||||
'0xd5eeac01b0d1d929d6cffaaf78020af137277293',
|
|
||||||
'0x88e49f9fd4cc3d30f2f46c652f59fb52c4874f23',
|
|
||||||
'0xabefbc9fd2f806065b4f3c237d4b59d9a97bcac7',
|
|
||||||
'0xd945f759d422ae30a6166838317b937de08380e3',
|
|
||||||
'0x8e52fb89b6311bd9ec36bd7cea9a0c311fd27a92',
|
|
||||||
'0x2079c2765462af6d78a9ccbddb6ff3c6d4ba2e24',
|
|
||||||
'0xd4d871419714b778ebec2e22c7c53572b573706e',
|
|
||||||
]
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
export * from './asset'
|
export * from './asset'
|
||||||
|
export * from './blocklist'
|
||||||
export * from './buildActivityAsset'
|
export * from './buildActivityAsset'
|
||||||
export * from './buildSellObject'
|
export * from './buildSellObject'
|
||||||
export * from './carousel'
|
export * from './carousel'
|
||||||
|
Loading…
Reference in New Issue
Block a user