Skip to content

Commit

Permalink
Merge pull request #10907 from hassnian/main
Browse files Browse the repository at this point in the history
fix: bad quality genart Image downloading & NFT with gif not animating
  • Loading branch information
vikiival authored Aug 26, 2024
2 parents c9fdef4 + 547656d commit 3a359b2
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 25 deletions.
7 changes: 6 additions & 1 deletion components/gallery/GalleryItemButton/GalleryItemButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
</div>

<GalleryItemMoreActionBtn
:ipfs-image="nftMetadata?.image"
:image-url="nftMetadata?.image"
:image-data="imageData"
:mime-type="nftMimeType"
:name="nft?.name"
:nft-sn="nft?.sn"
Expand All @@ -26,7 +27,9 @@ import { extractTwitterIdFromDescription } from '@/utils/parse'
const props = defineProps<{
galleryItem: GalleryItem
}>()
const { $i18n } = useNuxtApp()
const imageData = ref()
const nft = computed(() => props.galleryItem.nft.value)
const nftMimeType = computed(() => props.galleryItem.nftMimeType.value)
const nftMetadata = computed(() => props.galleryItem.nftMetadata.value)
Expand All @@ -38,6 +41,8 @@ const customSharingContent = computed(() => {
return twitterId ? $i18n.t('sharing.nftWithArtist', [twitterId]) : ''
})
onKodahashRenderCompleted(({ payload }) => imageData.value = payload.image)
</script>

<style scoped lang="scss">
Expand Down
57 changes: 33 additions & 24 deletions components/gallery/GalleryItemButton/GalleryItemMoreActionBtn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ const props = defineProps<{
nftSn?: string
collectionId?: string
collectionName?: string
ipfsImage?: string
imageUrl?: string
currentOwner?: string
price?: string
imageData?: string
}>()
const action = ref('')
Expand All @@ -85,34 +86,42 @@ const signingModalTitle = computed(() => {
const isDownloadEnabled = computed(() => {
const mimeType = props.mimeType
return (
return ((
(mimeType?.includes('image') || mimeType?.includes('text/html'))
&& props.ipfsImage
&& props.imageUrl) || props.imageData
)
})
const downloadMedia = () => {
const ipfsImage = props.ipfsImage
const downloadMedia = async () => {
let imageUrl = sanitizeIpfsUrl(props.imageUrl)
if (!imageUrl) {
return
}
if (ipfsImage) {
const originalUrl = props.mimeType?.includes('image')
? toOriginalContentUrl(ipfsImage)
: sanitizeIpfsUrl(ipfsImage)
if (isMobileDevice) {
toast($i18n.t('toast.downloadOnMobile'))
setTimeout(() => {
window.open(originalUrl, '_blank')
}, 2000)
return
}
try {
downloadImage(originalUrl, `${props.collectionName}_${props.name}`)
}
catch (error) {
$consola.warn('[ERR] unable to fetch image')
toast($i18n.t('toast.downloadError'))
return
}
if (props.imageData) {
const blob = await $fetch<Blob>(props.imageData)
imageUrl = URL.createObjectURL(blob)
}
else if (props.mimeType?.includes('image')) {
imageUrl = toOriginalContentUrl(imageUrl)
}
if (isMobileDevice) {
toast($i18n.t('toast.downloadOnMobile'))
setTimeout(() => {
window.open(imageUrl, '_blank')
}, 2000)
return
}
try {
toast($i18n.t('toast.downloadImage'))
downloadImage(imageUrl, `${props.collectionName}_${props.name}`)
}
catch (error) {
$consola.warn('[ERR] unable to fetch image')
toast($i18n.t('toast.downloadError'))
}
}
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,7 @@
"toast": {
"urlCopy": "URL copied to clipboard ✓",
"paymentLinkCopy": "Payment link copied to clipboard",
"downloadImage": "Downloading image",
"downloadError": "Unable to download image",
"unsupportedOperation": "Unsupported action",
"uploadFileSizeLimit": "The uploaded file exceeds the {0}MB size limit.",
Expand Down
22 changes: 22 additions & 0 deletions utils/kodahash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useEventListener } from '@vueuse/core'

type KodaHashEventType = 'kodahash/render/completed'

type KodasHashEvent = {
type: KodaHashEventType
payload: {
hash: string
image: string
type: string
search: string
attributes: unknown[]
}
}

export const onKodahashRenderCompleted = (callback: (event: KodasHashEvent) => void) => {
useEventListener(window, 'message', (e: MessageEvent<KodasHashEvent>) => {
if (e.data?.type === 'kodahash/render/completed' && e.data.payload) {
callback(e.data)
}
})
}

0 comments on commit 3a359b2

Please sign in to comment.