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

chore: pass metadata instead of full publication in getThumbnailUrl #1776

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/web/src/components/Shared/Audio/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const Audio: FC<Props> = ({ src, isNew = false, publication, txn, expandCover })
<div className="flex flex-wrap md:flex-nowrap md:space-x-2">
<CoverImage
isNew={isNew && !txn}
cover={isNew ? txn?.cover ?? audioPublication.cover : getThumbnailUrl(publication)}
cover={isNew ? txn?.cover ?? audioPublication.cover : getThumbnailUrl(publication?.metadata)}
setCover={(url, mimeType) =>
setAudioPublication({ ...audioPublication, cover: url, coverMimeType: mimeType })
}
Expand Down
11 changes: 4 additions & 7 deletions apps/web/src/lib/getThumbnailUrl.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { STATIC_IMAGES_URL } from 'data/constants';
import type { Publication } from 'lens';
import type { MetadataOutput } from 'lens';
import getIPFSLink from 'utils/getIPFSLink';

/**
*
* @param publication - The publication to get the thumbnail url from
* @returns the thumbnail url from a publication
*/
const getThumbnailUrl = (publication: Publication | undefined): string => {
if (!publication) {
const getThumbnailUrl = (metadata?: MetadataOutput): string => {
if (!metadata) {
return '';
}
const url =
publication.metadata?.cover?.original.url ||
publication.metadata?.image ||
`${STATIC_IMAGES_URL}/placeholder.webp`;

const url = metadata?.cover?.original.url || metadata?.image || `${STATIC_IMAGES_URL}/placeholder.webp`;
return getIPFSLink(url);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/getIPFSLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const getIPFSLink = (hash: string): string => {
if (!hash) {
return '';
}
const gateway = IPFS_GATEWAY;

const gateway = IPFS_GATEWAY;
return hash
.replace(/^Qm[1-9A-Za-z]{44}/gm, `${gateway}${hash}`)
.replace('https://ipfs.io/ipfs/', gateway)
Expand Down