Repository navigation
Simplify image preview logic #21085
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
base: main
Are you sure you want to change the base?
Simplify image preview logic #21085
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -33,7 +33,12 @@ | |||||||||||||||
| <i | ||||||||||||||||
| v-else | ||||||||||||||||
| aria-hidden="true" | ||||||||||||||||
| class="absolute inset-0 m-auto icon-[lucide--image] text-muted-foreground" | ||||||||||||||||
| :class=" | ||||||||||||||||
| cn( | ||||||||||||||||
| 'absolute inset-0 m-auto text-muted-foreground', | ||||||||||||||||
| iconName ?? 'icon-[lucide--image]' | ||||||||||||||||
| ) | ||||||||||||||||
| " | ||||||||||||||||
|
Comment on lines
+36
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P3] Keep the broken-image icon when a preview fails to load (C5) This branch runs only after the
Suggested change
|
||||||||||||||||
| /> | ||||||||||||||||
| </div> | ||||||||||||||||
| <div | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||||||||||||||||||
| import type { AssetItem } from '@/platform/assets/schemas/assetSchema' | ||||||||||||||||||||||
| import { resolveMediaSrc } from '@/platform/assets/utils/assetUrlUtil' | ||||||||||||||||||||||
| import { iconForFilename } from '@/platform/assets/utils/mediaIconUtil' | ||||||||||||||||||||||
| import { getMediaTypeFromFilename } from '@/utils/formatUtil' | ||||||||||||||||||||||
| import { hdrPreviewAssetUrl, isHdrImageFilename } from '@/utils/hdrFormatUtil' | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Import for the HDR URL check in
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| export interface Thumbnail { | ||||||||||||||||||||||
| src?: string | ||||||||||||||||||||||
| icon: string | ||||||||||||||||||||||
| isVideo: boolean | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+7
to
+11
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P3] Nit: "thumbnail" now names two things (M10) Inside |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| type ThumbnailSource = Pick<AssetItem, 'name'> & | ||||||||||||||||||||||
| Partial<Pick<AssetItem, 'preview_id' | 'preview_url' | 'thumbnail_url'>> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| function thumbnailSrc(asset: ThumbnailSource): string | undefined { | ||||||||||||||||||||||
| if (isHdrImageFilename(asset.name)) | ||||||||||||||||||||||
| return asset.preview_id | ||||||||||||||||||||||
| ? hdrPreviewAssetUrl(asset.preview_id) | ||||||||||||||||||||||
| : resolveMediaSrc(asset.thumbnail_url) || undefined | ||||||||||||||||||||||
|
Comment on lines
+17
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Keep raw HDR files out of the thumbnail src (C3) Base passed both URLs through This needs the import change in the next comment; T2 adds the table row that catches it.
Suggested change
|
||||||||||||||||||||||
| const mediaType = getMediaTypeFromFilename(asset.name) | ||||||||||||||||||||||
| if (mediaType === 'image') | ||||||||||||||||||||||
| return ( | ||||||||||||||||||||||
| resolveMediaSrc(asset.thumbnail_url || asset.preview_url) || undefined | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
|
Comment on lines
+22
to
+25
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Cloud image options now show the thumbnail's size, not the image's (C4) Image items load The precedence matches the policy |
||||||||||||||||||||||
| if (mediaType === 'video') | ||||||||||||||||||||||
| return resolveMediaSrc(asset.preview_url) || undefined | ||||||||||||||||||||||
| return undefined | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep explicit preview URLs for non-image, non-video model assets.
Suggested fix
Committable suggestion
|
||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| export function assetThumbnail(asset: ThumbnailSource): Thumbnail { | ||||||||||||||||||||||
| return { | ||||||||||||||||||||||
| src: thumbnailSrc(asset), | ||||||||||||||||||||||
| icon: iconForFilename(asset.name), | ||||||||||||||||||||||
| isVideo: getMediaTypeFromFilename(asset.name) === 'video' | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| import type { MediaKind } from '@/platform/assets/schemas/mediaAssetSchema' | ||
| import { getMediaTypeFromFilename } from '@/utils/formatUtil' | ||
| import { isHdrImageFilename } from '@/utils/hdrFormatUtil' | ||
|
|
||
| export function iconForMediaType(mediaType: MediaKind): string { | ||
| switch (mediaType) { | ||
|
|
@@ -16,3 +18,9 @@ export function iconForMediaType(mediaType: MediaKind): string { | |
| return 'icon-[lucide--image]' | ||
| } | ||
| } | ||
|
|
||
| export function iconForFilename(filename: string): string { | ||
| return isHdrImageFilename(filename) | ||
| ? 'icon-[lucide--sun]' | ||
| : iconForMediaType(getMediaTypeFromFilename(filename)) | ||
| } | ||
|
Comment on lines
+22
to
+26
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2]
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P3] Nit: build the row's thumbnail once (M5)
Each row calls
assetThumbnail(item.asset)three times and reads one field from each, and line 26 classifies the name a fourth time. Template function calls are not cached. One bag keeps the field mapping in one place:v-bind="thumbnailProps(item.asset)" :preview-alt="getAssetDisplayName(item.asset)"The function goes where the deleted helpers were, which crosses removed lines, so this is prose.