Skip to content
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
3 changes: 3 additions & 0 deletions src/components/sidebar/tabs/AssetsSidebarListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import {
getMediaTypeFromFilename,
truncateFilename
} from '@/utils/formatUtil'
import { hdrPreviewAssetUrl, isHdrImageFilename } from '@/utils/hdrFormatUtil'
import { cn } from '@comfyorg/tailwind-utils'

const {
Expand Down Expand Up @@ -139,6 +140,8 @@ function isVideoAsset(asset: AssetItem): boolean {

function getAssetPreviewUrl(asset: AssetItem): string {
const mediaType = getAssetMediaType(asset)
if (asset.preview_id && isHdrImageFilename(asset.name))
return hdrPreviewAssetUrl(asset.preview_id)
if (mediaType === 'image' || mediaType === 'video') {
return asset.preview_url || ''
}
Expand Down
11 changes: 9 additions & 2 deletions src/platform/assets/components/AssetsListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div
class="relative flex items-center gap-2 overflow-hidden rounded-lg p-2 select-none"
:aria-describedby="
videoStatus === 'failed' ? videoFailedDescriptionId : undefined

Check failure on line 5 in src/platform/assets/components/AssetsListItem.vue

View workflow job for this annotation

GitHub Actions / fallow / fallow

High complexity (critical)

Function '<template>' exceeds both complexity thresholds: • Severity: critical • Cyclomatic: 24 (threshold: 20) • Cognitive: 40 (threshold: 15) • Lines: 226 Consider splitting this function into smaller, focused functions.
"
>
<div
Expand Down Expand Up @@ -61,11 +61,17 @@
/>
</template>
<img
v-else
v-else-if="failedImageUrl !== previewUrl"
:src="previewUrl"
:alt="previewAlt"
class="size-full object-cover"
:draggable="false"
@error="failedImageUrl = previewUrl"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 (optional): failedImageUrl latches the first URL that fails and never retries it. A transient error, or a preview that isn't readable yet right after a job completes, leaves the row on the fallback icon until the URL changes or the row remounts. The video branch handles the same case with useRetryableMediaSrc (line 213), and MediaImageTop.vue uses useImageQuiet, so this component now has two failure models for one prop. Passing images through useRetryableMediaSrc(() => previewUrl) as well would leave one. Prose because whether image previews should retry is your call.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not terribly concerned given that the fallback image icon is rather graceful already and this is a preview in one of the many view areas.

Will plan to remove this section entirely when there's not risk of fallback to unsupported endpoints on the backend.

/>
<i
v-else
aria-hidden="true"
class="absolute inset-0 m-auto icon-[lucide--image] size-4 text-text-secondary"
/>
Comment on lines +71 to 75

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 (optional): The fallback always shows the image icon. The sidebar now sends previews for 3D and audio items, and job rows pass job-state icons through iconName, so a failed preview shows the wrong kind of item. The no-preview branch below (lines 82-91) already uses iconName ?? 'icon-[lucide--image]'.

Suggested change
<i
v-else
aria-hidden="true"
class="absolute inset-0 m-auto icon-[lucide--image] size-4 text-text-secondary"
/>
<i
v-else
aria-hidden="true"
:class="
cn(
'absolute inset-0 m-auto',
iconName ?? 'icon-[lucide--image]',
'size-4 text-text-secondary'
)
"
/>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very low likelihood, but agreed. Will hit in a followup PR

</div>
<div
Expand Down Expand Up @@ -154,7 +160,7 @@
</template>

<script setup lang="ts">
import { useId } from 'vue'
import { ref, useId } from 'vue'

import { useRetryableMediaSrc } from '@/composables/media/useRetryableMediaSrc'
import { useProgressBarBackground } from '@/composables/useProgressBarBackground'
Expand Down Expand Up @@ -207,6 +213,7 @@
} = useRetryableMediaSrc(() => (isVideoPreview ? previewUrl : undefined))

const videoFailedDescriptionId = useId()
const failedImageUrl = ref<string>()

const {
progressBarContainerClass,
Expand Down
12 changes: 12 additions & 0 deletions src/platform/assets/components/MediaAssetCard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,18 @@ describe('MediaAssetCard', () => {
expect(emitted().zoom).toEqual([[asset]])
})

it('previews an exr asset from its preview_url', async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deja vu...

const previewUrl = '/api/assets/exr-preview/content'
renderCard({
loading: false,
asset: { ...asset, name: 'render.exr', preview_url: previewUrl }
})

expect(
await screen.findByRole('img', { name: 'render.exr' })
).toHaveAttribute('src', previewUrl)
})

it('selects non-video assets from the preview', async () => {
const user = userEvent.setup()
const { container, emitted } = renderCard({
Expand Down
2 changes: 2 additions & 0 deletions src/platform/assets/components/MediaAssetCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ import {
getMediaTypeFromFilename,
isPreviewableMediaType
} from '@/utils/formatUtil'
import { isHdrImageFilename } from '@/utils/hdrFormatUtil'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 (optional): Import for the previewKind check on lines 258-261.

Suggested change
import { isHdrImageFilename } from '@/utils/hdrFormatUtil'
import { isHdrImageFilename, isHdrImageUrl } from '@/utils/hdrFormatUtil'


import { getAssetType } from '../composables/media/assetMappers'
import { startAssetDrag } from '../utils/assetDragUtil'
Expand Down Expand Up @@ -255,6 +256,7 @@ const fileKind = computed((): MediaKind => {
})

const previewKind = computed((): PreviewKind => {
if (asset?.preview_url && isHdrImageFilename(asset.name)) return 'image'
return getMediaTypeFromFilename(asset?.name || '')
})
Comment on lines 258 to 261

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 (optional): History-backed assets always have a preview_url, and for outputs it is resultItemUrl(output), the raw /view?filename=x.exr (assetMappers.ts:58-59, outputAssetUtil.ts:81-82). So an EXR without a backend preview now gets previewKind === 'image' and the card renders the whole EXR in an <img>, which fails. On base it showed the generic file tile. The card's image src is thumbnail_url || preview_url (line 281), so the check should look at that URL and treat the EXR as an image only when it points at something other than an HDR file. The suggestion also reuses fileKind, which already computes getMediaTypeFromFilename(asset?.name || ''). It needs the import suggested on line 178.

Suggested change
const previewKind = computed((): PreviewKind => {
if (asset?.preview_url && isHdrImageFilename(asset.name)) return 'image'
return getMediaTypeFromFilename(asset?.name || '')
})
const previewKind = computed((): PreviewKind => {
const previewSrc = asset?.thumbnail_url || asset?.preview_url
if (
previewSrc &&
isHdrImageFilename(asset?.name) &&
!isHdrImageUrl(previewSrc)
)
return 'image'
return fileKind.value
})


Expand Down
3 changes: 2 additions & 1 deletion src/platform/remote/comfyui/execution/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const zResultItem = z.object({
subfolder: z.string().optional(),
type: resultItemType.optional(),
display_name: z.string().optional(),
id: z.string().optional()
id: z.string().optional(),
preview_id: z.string().optional()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 (optional), question: z.string().optional() rejects null. Before this line the key was stripped, so any value was harmless. Now a job whose output carries preview_id: null fails zJobDetail.parse, and fetchJobDetail drops that job's outputs (I reproduced the parse failure with safeParse). ComfyUI#16898 omits the key when there is no preview, but the asset contract for the same field is .nullish(), and I couldn't confirm what cloud sends. If null is possible, normalizing it keeps ResultItem.preview_id as string | undefined, the same way assetSchema.ts normalizes user_metadata. A plain .nullish() breaks the URLSearchParams spreads in nodeOutputStore.ts:145 and savedImageUrls.ts:19; this version passes pnpm typecheck.

Suggested change
preview_id: z.string().optional()
preview_id: z
.string()
.nullish()
.transform((id) => id ?? undefined)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been conferring with Simon on the backend. And I believe there'es guarantee that the value will always be present and set to the real asset id when no preview has been assigned. The premise, however, is good. Will be certain to make use of it in the future.

})
export type ResultItem = z.infer<typeof zResultItem>
// Uses .passthrough() because custom nodes can output arbitrary keys.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useTelemetry } from '@/platform/telemetry'
import { downloadFile } from '@/base/common/downloadUtil'
import type { ResultItem } from '@/platform/remote/comfyui/execution/types'
import ImagePreview from '@/renderer/extensions/vueNodes/components/ImagePreview.vue'
import { openHdrViewer } from '@/services/hdrViewerService'
import { useNodeOutputStore } from '@/stores/nodeOutputStore'
import { createMockLGraphNode } from '@/utils/__tests__/litegraphTestUtils'
import { resolveNode } from '@/utils/litegraphUtil'
Expand Down Expand Up @@ -168,6 +169,21 @@ describe('ImagePreview', () => {
expect(screen.queryByTestId('main-image')).not.toBeInTheDocument()
})

it('shows the server preview of an exr output and still offers the HDR viewer', async () => {
const exrUrl = '/api/view?filename=out.exr&type=output&preview_id=p1'
renderImagePreview({ imageUrls: [exrUrl] })
const user = userEvent.setup()

expect(screen.getByTestId('main-image')).toHaveAttribute(
'src',
'/api/assets/p1/content?disposition=inline'
)

await user.click(screen.getByRole('button', { name: 'Open in HDR Viewer' }))

expect(openHdrViewer).toHaveBeenCalledWith(exrUrl)
})

it('displays calculating dimensions text in gallery mode', async () => {
renderImagePreview({
imageUrls: [defaultProps.imageUrls[0]]
Expand Down
58 changes: 42 additions & 16 deletions src/renderer/extensions/vueNodes/components/ImagePreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,22 @@
"
@click="handleGridClick(index)"
>
<img
v-if="!isHdrImageUrl(imageUrls[index])"
:src="url"
:alt="`${$t('g.galleryThumbnail')} ${index + 1}`"
draggable="false"
class="pointer-events-none size-full object-contain"
@load="updateAspectRatio($event, index)"
/>
<div
v-if="!isHdrPlaceholder(imageUrls[index])"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 (optional): Part of the computed change on lines 309-318.

Suggested change
v-if="!isHdrPlaceholder(imageUrls[index])"
v-if="!hdrPlaceholders[index]"

class="pointer-events-none relative size-full"
>
<img
:src="url"
:alt="`${$t('g.galleryThumbnail')} ${index + 1}`"
draggable="false"
class="size-full object-contain"
@load="updateAspectRatio($event, index)"
/>
<i
v-if="isHdrImageUrl(imageUrls[index])"
class="absolute top-1 left-1 icon-[lucide--sun] size-4 text-base-foreground drop-shadow-sm"
/>
Comment on lines +40 to +43

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 (optional): Part of the computed change on lines 309-318. Inside the non-placeholder branch, an HDR URL always has a preview, so hdrPreviewUrls[index] gives the same answer without another parse. I also added aria-hidden, since the badge is decorative, matching the fallback icon this PR adds in AssetsListItem.vue.

Suggested change
<i
v-if="isHdrImageUrl(imageUrls[index])"
class="absolute top-1 left-1 icon-[lucide--sun] size-4 text-base-foreground drop-shadow-sm"
/>
<i
v-if="hdrPreviewUrls[index]"
aria-hidden="true"
class="absolute top-1 left-1 icon-[lucide--sun] size-4 text-base-foreground drop-shadow-sm"
/>

</div>
<div
v-else
class="flex size-full flex-col items-center justify-center gap-1 text-base-foreground"
Expand Down Expand Up @@ -84,13 +92,13 @@
</div>
<!-- Loading State -->
<div
v-if="showLoader && !imageError && !currentImageIsHdr"
v-if="showLoader && !imageError && !isHdrPlaceholder(currentImageUrl)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 (optional): Part of the computed change on lines 309-318.

Suggested change
v-if="showLoader && !imageError && !isHdrPlaceholder(currentImageUrl)"
v-if="showLoader && !imageError && !currentImageIsHdrPlaceholder"

class="size-full"
>
<Skeleton class="size-full rounded-sm" />
</div>
<button
v-if="!imageError && currentImageIsHdr"
v-if="!imageError && isHdrPlaceholder(currentImageUrl)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 (optional): Part of the computed change on lines 309-318.

Suggested change
v-if="!imageError && isHdrPlaceholder(currentImageUrl)"
v-if="!imageError && currentImageIsHdrPlaceholder"

type="button"
data-testid="hdr-open-button"
class="absolute inset-0 flex cursor-pointer flex-col items-center justify-center gap-3 border-0 bg-transparent text-base-foreground"
Expand All @@ -106,9 +114,9 @@
</button>
<!-- Main Image -->
<img
v-if="!imageError && !currentImageIsHdr"
v-if="!imageError && !isHdrPlaceholder(currentImageUrl)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 (optional): Part of the computed change on lines 309-318.

Suggested change
v-if="!imageError && !isHdrPlaceholder(currentImageUrl)"
v-if="!imageError && !currentImageIsHdrPlaceholder"

data-testid="main-image"
:src="currentImageUrl"
:src="currentHdrPreviewUrl ?? currentImageUrl"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 (optional): Rendering the preview here means handleImageLoad now fires for HDR outputs and calls nodeOutputStore.syncLegacyNodeImgs(nodeId, img, currentIndex.value) with the preview element. On base, HDR outputs never loaded this <img>, so node.imgs stayed empty. Now the node context menu's Open Image, Copy Image and Save Image (litegraphService.ts:717-745) act on the tonemapped preview, and Save reads its filename from searchParams, which is null for this URL. isImageNode (litegraphUtil.ts:78-83) also turns on the mask editor and clipspace for the 8-bit preview. The fix is in handleImageLoad, outside this diff, so I can't attach a suggestion:

  if (nodeId && !currentHdrPreviewUrl.value) {
    nodeOutputStore.syncLegacyNodeImgs(nodeId, img, currentIndex.value)
  }

:alt="imageAltText"
draggable="false"
class="pointer-events-none absolute inset-0 block size-full object-contain"
Expand All @@ -131,6 +139,16 @@
<i-comfy:mask class="size-4" />
</button>

<button
Comment thread
DrJKL marked this conversation as resolved.
Resolved
v-if="!imageError && currentHdrPreviewUrl"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 (optional): When the preview fails to load (the cloud workspace case from the description, or a preview removed by ComfyUI#16898's reclaim cascade), imageError hides this button. The full-size HDR placeholder button is hidden too, because the placeholder check is false whenever a preview_id exists, and a grid click goes to the error state. On base every EXR output could open the HDR viewer. The actions bar is outside the error v-if, so dropping !imageError keeps the viewer reachable.

Suggested change
v-if="!imageError && currentHdrPreviewUrl"
v-if="currentHdrPreviewUrl"

:class="actionButtonClass"
:title="$t('hdrViewer.openInHdrViewer')"
:aria-label="$t('hdrViewer.openInHdrViewer')"
@click="openHdrViewer(currentImageUrl)"
>
<i class="icon-[lucide--sun] size-4" />
</button>

<!-- Layer Editor Button -->
<button
v-if="hasMultipleImages && !imageError"
Expand Down Expand Up @@ -168,7 +186,7 @@

<!-- Image Dimensions (gallery mode only) -->
<div
v-if="viewMode === 'gallery' && !currentImageIsHdr"
v-if="viewMode === 'gallery' && !isHdrPlaceholder(currentImageUrl)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 (optional): Part of the computed change on lines 309-318.

Suggested change
v-if="viewMode === 'gallery' && !isHdrPlaceholder(currentImageUrl)"
v-if="viewMode === 'gallery' && !currentImageIsHdrPlaceholder"

class="pt-2 text-center text-xs text-base-foreground"
>
<span
Expand Down Expand Up @@ -235,7 +253,7 @@ import { useToast } from '@/components/ui/toast/toastStore'
import { openHdrViewer } from '@/services/hdrViewerService'
import { useNodeOutputStore } from '@/stores/nodeOutputStore'
import type { NodeId } from '@/types/nodeId'
import { isHdrImageUrl } from '@/utils/hdrFormatUtil'
import { getHdrPreviewUrl, isHdrImageUrl } from '@/utils/hdrFormatUtil'
import { getGridThumbnailUrl } from '@/utils/imageUtil'
import { resolveNode } from '@/utils/litegraphUtil'
import { cn } from '@comfyorg/tailwind-utils'
Expand Down Expand Up @@ -288,8 +306,16 @@ const { start: startDelayedLoader, stop: stopDelayedLoader } = useTimeoutFn(
)

const currentImageUrl = computed(() => imageUrls[currentIndex.value] ?? '')
const isHdrPlaceholder = (url: string | undefined) =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this not also be a computed?

isHdrImageUrl(url) && !getHdrPreviewUrl(url)

const currentImageIsHdr = computed(() => isHdrImageUrl(currentImageUrl.value))
const gridImageUrls = computed(() => imageUrls.map(getGridThumbnailUrl))
const currentHdrPreviewUrl = computed(() =>
getHdrPreviewUrl(currentImageUrl.value)
)
const gridImageUrls = computed(() =>
imageUrls.map((url) => getHdrPreviewUrl(url) ?? getGridThumbnailUrl(url))
)
Comment on lines +309 to +318

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 (optional): Following up on the computed question at line 309: the HDR state is derived by function calls spread across the template (isHdrPlaceholder(...) at lines 30, 95, 101, 117, 189 and in handleGridClick, isHdrImageUrl(imageUrls[index]) at line 41), and each call re-parses its URL, two or three times per grid cell per render. Two array computeds cover the grid and two per-image computeds cover the current image. The badge needs no extra array: inside the non-placeholder branch, an HDR URL always has a preview URL. The companion suggestions on lines 30, 40-43, 95, 101, 117, 189 and 450 switch the call sites. I applied all of them together: pnpm typecheck, oxlint, oxfmt and the ImagePreview tests pass.

Suggested change
const isHdrPlaceholder = (url: string | undefined) =>
isHdrImageUrl(url) && !getHdrPreviewUrl(url)
const currentImageIsHdr = computed(() => isHdrImageUrl(currentImageUrl.value))
const gridImageUrls = computed(() => imageUrls.map(getGridThumbnailUrl))
const currentHdrPreviewUrl = computed(() =>
getHdrPreviewUrl(currentImageUrl.value)
)
const gridImageUrls = computed(() =>
imageUrls.map((url) => getHdrPreviewUrl(url) ?? getGridThumbnailUrl(url))
)
const hdrPreviewUrls = computed(() =>
imageUrls.map((url) => getHdrPreviewUrl(url))
)
const hdrPlaceholders = computed(() =>
imageUrls.map(
(url, index) => isHdrImageUrl(url) && !hdrPreviewUrls.value[index]
)
)
const currentImageIsHdr = computed(() => isHdrImageUrl(currentImageUrl.value))
const currentHdrPreviewUrl = computed(
() => hdrPreviewUrls.value[currentIndex.value]
)
const currentImageIsHdrPlaceholder = computed(
() => hdrPlaceholders.value[currentIndex.value] ?? false
)
const gridImageUrls = computed(() =>
imageUrls.map(
(url, index) => hdrPreviewUrls.value[index] ?? getGridThumbnailUrl(url)
)
)

const hasMultipleImages = computed(() => imageUrls.length > 1)
const canExportOutputs = computed(() => {
const node = nodeId ? resolveNode(nodeId) : undefined
Expand Down Expand Up @@ -421,7 +447,7 @@ async function openImageInGallery(index: number) {

function handleGridClick(index: number) {
const url = imageUrls[index]
if (isHdrImageUrl(url)) {
if (isHdrPlaceholder(url)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 (optional): Part of the computed change on lines 309-318.

Suggested change
if (isHdrPlaceholder(url)) {
if (hdrPlaceholders.value[index]) {

openHdrViewer(url)
return
}
Expand Down
15 changes: 15 additions & 0 deletions src/stores/nodeOutputStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ describe('nodeOutputStore setNodeOutputsByExecutionId with merge', () => {
expect(previewUrl.searchParams.get('type')).toBe('output')
})

it('carries preview_id on the view URL', () => {
const store = useNodeOutputStore()
const node = createMockNode({ id: 1 })

store.setNodeOutputsByExecutionId(
createNodeExecutionId([node.id]),
createMockOutputs([{ filename: 'render.exr', preview_id: 'preview-1' }])
)

const [url] = store.getNodeImageUrls(node) ?? []
const viewUrl = new URL(url, window.location.origin)
expect(viewUrl.pathname).toBe('/api/view')
expect(viewUrl.searchParams.get('preview_id')).toBe('preview-1')
})

it('owns preview arrays after setting them', () => {
const store = useNodeOutputStore()
const executionId = createNodeExecutionId([toNodeId(11)])
Expand Down
19 changes: 19 additions & 0 deletions src/utils/hdrFormatUtil.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest'

import {
getHdrPreviewUrl,
getImageFilenameFromUrl,
isHdrImageFilename,
isHdrImageUrl,
Expand Down Expand Up @@ -55,6 +56,24 @@ describe('isHdrImageUrl', () => {
})
})

describe('getHdrPreviewUrl', () => {
it.for([
{
url: '/api/view?filename=scene.exr&preview_id=p1',
expected: '/api/assets/p1/content?disposition=inline'
},
{
url: '/api/view?filename=scene.HDR&preview_id=p1',
expected: '/api/assets/p1/content?disposition=inline'
},
Comment on lines +65 to +68

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 (optional): Every input that reaches the asset URL uses the id p1, so a hdrPreviewAssetUrl that ignored its argument and returned p1 passes the whole suite. I ran that mutation. A different id on this row catches it.

Suggested change
{
url: '/api/view?filename=scene.HDR&preview_id=p1',
expected: '/api/assets/p1/content?disposition=inline'
},
{
url: '/api/view?filename=scene.HDR&preview_id=p2',
expected: '/api/assets/p2/content?disposition=inline'
},

{ url: '/api/view?filename=scene.exr', expected: undefined },
{ url: '/api/view?filename=scene.png&preview_id=p1', expected: undefined },
{ url: undefined, expected: undefined }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 (optional): The undefined row repeats isHdrImageUrl(undefined), which is already tested above, and removing the url && guard leaves it green. A malformed URL is the input that currently throws (TypeError: Invalid URL), so it deserves the row instead. It passes once getHdrPreviewUrl uses URL.parse (comment on hdrFormatUtil.ts:30-36).

Suggested change
{ url: undefined, expected: undefined }
{ url: 'http://[bad/out.exr', expected: undefined }

])('maps $url to $expected', ({ url, expected }) => {
expect(getHdrPreviewUrl(url)).toBe(expected)
})
})

describe('toFullResolutionUrl', () => {
it('strips the preview parameter', () => {
expect(
Expand Down
14 changes: 14 additions & 0 deletions src/utils/hdrFormatUtil.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { api } from '@/scripts/api'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 (optional): Import for the delegation in getHdrPreviewUrl (comment on lines 30-36).

Suggested change
import { api } from '@/scripts/api'
import { getPreviewAssetUrl } from '@/platform/assets/utils/assetUrlUtil'


const HDR_EXTENSIONS = ['.exr', '.hdr'] as const

export function isHdrImageFilename(filename: string | undefined): boolean {
Expand Down Expand Up @@ -25,6 +27,18 @@ export function isHdrImageUrl(url: string | undefined): boolean {
return isHdrImageFilename(getImageFilenameFromUrl(url))
}

export function getHdrPreviewUrl(url: string | undefined): string | undefined {
const previewId =
url &&
isHdrImageUrl(url) &&
new URL(url, window.location.origin).searchParams.get('preview_id')
return previewId ? hdrPreviewAssetUrl(previewId) : undefined
}
Comment thread
AustinMroz marked this conversation as resolved.
Resolved
Comment on lines +30 to +36

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 (optional): hdrPreviewAssetUrl below and assetPreviewUrl in assetUrlUtil.ts build the same /assets/${id}/content?disposition=inline string, so a workspace_id or encoding fix has to land twice. When I changed only one copy, every test stayed green. Delegating removes the copy. The same edit settles CodeRabbit's point about the unguarded new URL. isHdrImageUrl('http://[bad/out.exr') is true through the catch fallback in getImageFilenameFromUrl, and the second parse then throws inside the ImagePreview computeds. URL.parse returns null instead (assetDragUtil.ts already uses it), and the early return replaces the string | false | null | undefined union the && chain produced. This depends on the helper accepting null (comment on assetUrlUtil.ts:94-97) and on the import on line 1.

Suggested change
export function getHdrPreviewUrl(url: string | undefined): string | undefined {
const previewId =
url &&
isHdrImageUrl(url) &&
new URL(url, window.location.origin).searchParams.get('preview_id')
return previewId ? hdrPreviewAssetUrl(previewId) : undefined
}
export function getHdrPreviewUrl(url: string | undefined): string | undefined {
if (!url || !isHdrImageUrl(url)) return undefined
return getPreviewAssetUrl(
URL.parse(url, window.location.origin)?.searchParams.get('preview_id')
)
}


export function hdrPreviewAssetUrl(previewId: string): string {
return api.apiURL(`/assets/${previewId}/content?disposition=inline`)
}
Comment on lines +37 to +40

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 (optional): Unused after the delegation on lines 30-36.

Suggested change
function hdrPreviewAssetUrl(previewId: string): string {
return api.apiURL(`/assets/${previewId}/content?disposition=inline`)
}


export function toFullResolutionUrl(url: string): string {
try {
const parsed = new URL(url, window.location.origin)
Expand Down
43 changes: 43 additions & 0 deletions src/utils/resultItemUrl.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { describe, expect, it } from 'vitest'

import type { AugmentedResultItem } from '@/utils/resultItem'
import { resultItemPreviewUrl } from '@/utils/resultItemUrl'

function resultItem(
overrides: Partial<AugmentedResultItem>
): AugmentedResultItem {
return {
filename: 'out.png',
subfolder: '',
type: 'output',
nodeId: '3',
mediaType: 'images',
...overrides
}
}

describe('resultItemPreviewUrl', () => {
it.for([
{
filename: 'render.exr',
preview_id: 'p1',
pathname: '/api/assets/p1/content'
},
{
filename: 'render.HDR',
preview_id: 'p1',
pathname: '/api/assets/p1/content'
},
Comment on lines +26 to +30

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 (optional): resultItemPreviewUrl has no extension logic of its own beyond isHdrImageFilename, whose tests already cover case-insensitive matching. No mutation I ran separates this row from the render.exr row above.

Suggested change
{
filename: 'render.HDR',
preview_id: 'p1',
pathname: '/api/assets/p1/content'
},

{ filename: 'render.exr', preview_id: undefined, pathname: '/api/view' },
{ filename: 'render.png', preview_id: 'p1', pathname: '/api/view' }
])(
'resolves $filename with preview_id $preview_id to $pathname',
({ filename, preview_id, pathname }) => {
const url = new URL(
resultItemPreviewUrl(resultItem({ filename, preview_id })),
window.location.origin
)
expect(url.pathname).toBe(pathname)
}
)
})
3 changes: 3 additions & 0 deletions src/utils/resultItemUrl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { appendCloudResParam } from '@/platform/distribution/cloudPreviewUtil'
import { api } from '@/scripts/api'
import { hdrPreviewAssetUrl, isHdrImageFilename } from '@/utils/hdrFormatUtil'
import type { AugmentedResultItem } from '@/utils/resultItem'
import { isImageResult } from '@/utils/resultItem'

Expand All @@ -21,6 +22,8 @@ export function resultItemUrl(item: AugmentedResultItem): string {

export function resultItemPreviewUrl(item: AugmentedResultItem): string {
if (item.previewUrl !== undefined) return item.previewUrl
if (item.preview_id && isHdrImageFilename(item.filename))
return hdrPreviewAssetUrl(item.preview_id)
if (!isImageResult(item)) return resultItemUrl(item)
const params = resultItemUrlParams(item)
appendCloudResParam(params, item.filename)
Expand Down
Loading