Skip to content

Commit

Permalink
Merge branch 'main' into dev/mel-gql-experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
melMass committed Feb 22, 2023
2 parents 7b9577c + f893d99 commit f401e2e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
45 changes: 27 additions & 18 deletions src/context/mintStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '@constants'
import {
extensionFromMimetype,
generateCoverAndThumbnail,
getImageDimensions,
removeExtension,
} from '@utils/mint'
Expand Down Expand Up @@ -99,7 +100,6 @@ export const useMintStore = create<MintState>()(
description,
tags,
cover,
thumbnail,
photosensitive,
nsfw,
reset,
Expand Down Expand Up @@ -163,7 +163,14 @@ export const useMintStore = create<MintState>()(
MIMETYPE.ZIP1,
MIMETYPE.ZIP2,
].includes(artifact.mimeType)

const formats = []

const generated = await generateCoverAndThumbnail(artifact)

let used_cover = cover || generated.cover
let used_thumb = generated.thumbnail

if (artifact.mimeType.indexOf('image') === 0) {
const format: Format = {
mimeType: artifact.mimeType,
Expand Down Expand Up @@ -194,33 +201,35 @@ export const useMintStore = create<MintState>()(
// TMP: skip GIFs to avoid making static
if (artifact.mimeType !== MIMETYPE.GIF) {
let coverIsGif = false
if (cover) {
coverIsGif = cover.mimeType === MIMETYPE.GIF
if (used_cover) {
coverIsGif = used_cover.mimeType === MIMETYPE.GIF
const { imageWidth, imageHeight } = await getImageDimensions(
cover
used_cover
)
cover.format = {
mimeType: cover.mimeType,
fileSize: cover.buffer.byteLength,
used_cover.format = {
mimeType: used_cover.mimeType,
fileSize: used_cover.buffer.byteLength,
fileName: `${removeExtension(artifact.file.name)}.${
coverIsGif ? 'gif' : extensionFromMimetype(cover.mimeType)
coverIsGif
? 'gif'
: extensionFromMimetype(used_cover.mimeType)
}`,
dimensions: {
value: `${imageWidth}x${imageHeight}`,
unit: 'px',
},
}
}
if (thumbnail && !coverIsGif) {
if (used_thumb && !coverIsGif) {
const { imageWidth, imageHeight } = await getImageDimensions(
thumbnail
used_thumb
)
thumbnail.format = {
mimeType: thumbnail.mimeType,
fileSize: thumbnail.buffer.byteLength,
used_thumb.format = {
mimeType: used_thumb.mimeType,
fileSize: used_thumb.buffer.byteLength,
fileName: `${removeExtension(
artifact.file.name
)}.${extensionFromMimetype(thumbnail.mimeType)}`,
)}.${extensionFromMimetype(used_thumb.mimeType)}`,
dimensions: {
value: `${imageWidth}x${imageHeight}`,
unit: 'px',
Expand All @@ -241,8 +250,8 @@ export const useMintStore = create<MintState>()(
tags,
address: minterAddress,
files,
cover,
thumbnail,
cover: used_cover,
thumbnail: used_thumb,
generateDisplayUri: true,
rights: license?.value,
rightUri: custom_license_uri,
Expand All @@ -259,8 +268,8 @@ export const useMintStore = create<MintState>()(
tags,
address: minterAddress,
file: artifact,
cover,
thumbnail,
cover: used_cover,
thumbnail: used_thumb,

rights: license?.value,
rightUri: custom_license_uri,
Expand Down
4 changes: 2 additions & 2 deletions src/data/ipfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export const prepareFile = async ({
}

// upload cover image
let displayUri = ''
let displayUri = uri
if (generateDisplayUri && cover) {
const coverCid = await uploadFileToIPFSProxy({
blob: new Blob([cover.buffer]),
Expand All @@ -211,7 +211,7 @@ export const prepareFile = async ({

// upload thumbnail image
let thumbnailUri = IPFS_DEFAULT_THUMBNAIL_URI
if (generateDisplayUri && thumbnail) {
if (thumbnail) {
const thumbnailCid = await uploadFileToIPFSProxy({
blob: new Blob([thumbnail.buffer]),
path: `thumbnail_${
Expand Down

0 comments on commit f401e2e

Please sign in to comment.