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

fix: adjust imageSrc on carousel component #6599

Merged
merged 10 commits into from
Aug 10, 2023
18 changes: 6 additions & 12 deletions components/carousel/module/CarouselMedia.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,17 @@
<nuxt-link
:to="urlOf({ id: item.id, url, chain: item.chain })"
rel="nofollow">
<PreviewMediaResolver
v-if="item.animationUrl"
:src="item.animationUrl"
:poster="imageSrc || ''"
:metadata="item.metadata" />
<BasicImage
v-else
:src="imageSrc"
:alt="item.name"
custom-class="carousel__image-wrapper" />
vikiival marked this conversation as resolved.
Show resolved Hide resolved
<MediaItem
class="carousel__image-wrapper"
:src="item.image || ''"
:animation-src="item.animationUrl || ''"
:title="item.name" />
</nuxt-link>
</div>
</template>

<script lang="ts" setup>
import PreviewMediaResolver from '@/components/media/PreviewMediaResolver.vue'
import BasicImage from '@/components/shared/view/BasicImage.vue'
import { MediaItem } from '@kodadot1/brick'

import type { CarouselNFT } from '@/components/base/types'
import type { NFTWithMetadata } from '@/composables/useNft'
Expand Down
4 changes: 1 addition & 3 deletions components/common/ConnectWallet/WalletAssetNfts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
v-for="nft in nfts.slice(0, 3)"
:key="nft.id"
:href="`/${urlPrefix}/gallery/${nft.id}`">
<MediaItem
:src="sanitizeIpfsUrl(nft.meta.image)"
:mime-type="nft.type" />
<MediaItem :src="sanitizeIpfsUrl(nft.meta.image)" />
</a>
</div>
</div>
Expand Down
2 changes: 0 additions & 2 deletions components/gallery/GalleryItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
<MediaItem
:key="resource.src"
:src="resource.src"
:mime-type="resource.mimeType"
:animation-src="resource.animation"
is-detail />
</NeoCarouselItem>
Expand All @@ -52,7 +51,6 @@
class="gallery-item-media"
:src="nftImage"
:animation-src="nftAnimation"
:mime-type="nftMimeType"
:title="nftMetadata?.name"
is-detail
:is-lewd="galleryDescriptionRef?.isLewd"
Expand Down
39 changes: 26 additions & 13 deletions components/gallery/GalleryItemDescription.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,21 @@
<p>{{ nft?.royalty }}%</p>
</div>
<hr class="my-2" />
<div class="is-flex is-justify-content-space-between">
<div v-if="nftImage" class="is-flex is-justify-content-space-between">
<p>{{ $t('tabs.tabDetails.media') }}</p>
<a
:href="nftAnimation || nftImage"
target="_blank"
rel="nofollow noopener noreferrer"
class="has-text-link"
data-cy="media-link"
>{{ nftMimeType }}</a
>
<div @click="openLink(nftImage)">
<a class="has-text-link" data-cy="media-link">
{{ nftMimeType }}
</a>
</div>
</div>
<div v-if="nftAnimation" class="is-flex is-justify-content-space-between">
<p>{{ $t('tabs.tabDetails.animatedMedia') }}</p>
<div @click="openLink(nftAnimation)">
<a class="has-text-link">
{{ animationMediaMimeType }}
</a>
</div>
</div>
<div class="is-flex is-justify-content-space-between">
<p>{{ $t('tabs.tabDetails.metadata') }}</p>
Expand Down Expand Up @@ -121,7 +126,6 @@
class="gallery-parent-item"
:src="parent?.nftImage.value"
:animation-src="parent?.nftAnimation.value"
:mime-type="parent?.nftMimeType.value"
:title="parent?.nftMetadata?.value?.name"
is-detail />
<p class="gallery-parent-item__name">
Expand All @@ -143,12 +147,12 @@ import {
NeoTooltip,
} from '@kodadot1/brick'
import Identity from '@/components/identity/IdentityIndex.vue'
import { sanitizeIpfsUrl } from '@/utils/ipfs'
import { sanitizeIpfsUrl, toCloudflareIpfsUrl } from '@/utils/ipfs'

import { GalleryItem, useGalleryItem } from './useGalleryItem'

import { MediaType } from '@/components/rmrk/types'
import { resolveMedia } from '@/utils/gallery/media'
import { getMimeType, resolveMedia } from '@/utils/gallery/media'

import { replaceSingularCollectionUrlByText } from '@/utils/url'

Expand Down Expand Up @@ -218,10 +222,11 @@ const propertiesTabDisabled = computed(() => {

const metadataMimeType = ref('application/json')
const metadataURL = ref('')
const animationMediaMimeType = ref('')

watchEffect(async () => {
if (nft.value?.metadata) {
const sanitizeMetadata = sanitizeIpfsUrl(nft.value?.metadata)
const sanitizeMetadata = sanitizeIpfsUrl(nft.value?.metadata, 'cloudflare')
preschian marked this conversation as resolved.
Show resolved Hide resolved
const response = await fetch(sanitizeMetadata, {
method: 'HEAD',
})
Expand All @@ -230,5 +235,13 @@ watchEffect(async () => {
response.headers.get('content-type') || 'application/json'
metadataURL.value = sanitizeMetadata
}

if (nftAnimation.value) {
animationMediaMimeType.value = await getMimeType(nftAnimation.value)
preschian marked this conversation as resolved.
Show resolved Hide resolved
}
})

const openLink = (link) => {
window.open(toCloudflareIpfsUrl(link), '_blank')
}
</script>
2 changes: 0 additions & 2 deletions components/gallery/GalleryItemPreviewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
:src="itemSrc"
:placeholder="placeholder"
:animation-src="nftAnimation"
:mime-type="nftMimeType"
:title="nft?.name || nft?.id"
original />
</div>
Expand All @@ -38,7 +37,6 @@ const props = defineProps<{
}>()

const nft = computed(() => props.galleryItem.nft.value)
const nftMimeType = computed(() => props.galleryItem.nftMimeType.value)
const nftAnimation = computed(() => props.galleryItem.nftAnimation.value)

const emit = defineEmits(['input'])
Expand Down
3 changes: 2 additions & 1 deletion composables/useNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function getProcessMetadata(nft: NFTWithMetadata) {
const metadata = (await processSingleMetadata(
nft.metadata
)) as NFTWithMetadata
const image = sanitizeIpfsUrl(metadata.image || '')
const image = sanitizeIpfsUrl(metadata.image || metadata.mediaUri || '')
const animation_url = sanitizeIpfsUrl(metadata.animation_url || '')
const getAttributes = () => {
const hasMetadataAttributes =
Expand Down Expand Up @@ -79,6 +79,7 @@ export function getNftMetadata(nft: NFTWithMetadata, prefix: string) {
if (prefix === 'stmn') {
return getProcessMetadata(nft)
}

if (nft.meta && nft.meta.image) {
return getGeneralMetadata(nft)
}
Expand Down
8 changes: 2 additions & 6 deletions libs/ui/src/components/MediaItem/MediaItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ export default {
type: String,
default: '',
},
mimeType: {
type: String,
default: '',
},
title: {
type: String,
default: 'KodaDot NFT',
Expand Down Expand Up @@ -93,7 +89,7 @@ export default {
},
computed: {
resolveComponent() {
const type = this.mimeType || this.defaultMimeType
const type = this.defaultMimeType
return this.components[resolveMedia(type) + SUFFIX]
},
properSrc() {
Expand All @@ -110,7 +106,7 @@ export default {
},
methods: {
async updateComponent() {
if (this.animationSrc && !this.mimeType) {
if (this.animationSrc) {
preschian marked this conversation as resolved.
Show resolved Hide resolved
this.defaultMimeType = await getMimeType(this.animationSrc)
}
},
Expand Down
1 change: 0 additions & 1 deletion libs/ui/src/components/NeoNftCard/NeoNftCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
class="nft-media"
:src="nft.image"
:animation-src="nft.animationUrl"
:mime-type="nft.mimeType"
:placeholder="placeholder"
:title="nft?.name" />
<div
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@
"tokenStandard": "Token Standard",
"royalties": "Royalties",
"media": "Media",
"animatedMedia": "Animated Media",
"metadata": "Metadata"
},
"tabActivity": {
Expand Down
5 changes: 5 additions & 0 deletions utils/ipfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,8 @@ export type EntityWithMeta = {
metadata: string
meta?: NFTMetadata
}

export function toCloudflareIpfsUrl(baseurl) {
const url = new URL(baseurl)
return `https://cloudflare-ipfs.com/${url.pathname}`
}
Loading