Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(webv2): distinguish missing videos from failed lookups
joshistoast4c4e8abba76d
diff --git a/invokeai/frontend/webv2/src/workbench/projects/invk/assetTransport.test.ts b/invokeai/frontend/webv2/src/workbench/projects/invk/assetTransport.test.tsnew file mode 100644index 0000000000..4539aae469--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/projects/invk/assetTransport.test.ts@@ -0,0 +1,38 @@+import { ApiError } from '@platform/transport/http';+import { describe, expect, it, vi } from 'vitest';++const mocks = vi.hoisted(() => ({ apiFetchRaw: vi.fn() }));++vi.mock('@platform/transport/http', async (importOriginal) => ({+ ...(await importOriginal<typeof import('@platform/transport/http')>()),+ apiFetchRaw: mocks.apiFetchRaw,+}));++import { findExistingVideoNames } from './assetTransport';++describe('findExistingVideoNames', () => {+ it('returns a video name when its lookup succeeds', async () => {+ mocks.apiFetchRaw.mockResolvedValue(new Response(null, { status: 200 }));++ await expect(findExistingVideoNames(['present.mp4'])).resolves.toEqual(new Set(['present.mp4']));+ });++ it.each([403, 404])('treats a %i video lookup as absent', async (status) => {+ mocks.apiFetchRaw.mockResolvedValue(new Response(null, { status }));++ await expect(findExistingVideoNames(['missing.mp4'])).resolves.toEqual(new Set());+ });++ it.each([401, 422, 500])('rejects a %i video lookup with an ApiError', async (status) => {+ mocks.apiFetchRaw.mockResolvedValue(new Response('lookup failed', { status }));++ await expect(findExistingVideoNames(['failed.mp4'])).rejects.toBeInstanceOf(ApiError);+ });++ it('propagates a network rejection unchanged', async () => {+ const networkError = new Error('network unavailable');+ mocks.apiFetchRaw.mockRejectedValue(networkError);++ await expect(findExistingVideoNames(['unreachable.mp4'])).rejects.toBe(networkError);+ });+});diff --git a/invokeai/frontend/webv2/src/workbench/projects/invk/assetTransport.ts b/invokeai/frontend/webv2/src/workbench/projects/invk/assetTransport.tsindex b99b93a977..74b54ac801 100644--- a/invokeai/frontend/webv2/src/workbench/projects/invk/assetTransport.ts+++ b/invokeai/frontend/webv2/src/workbench/projects/invk/assetTransport.ts@@ -1,5 +1,5 @@import { mapWithConcurrency } from '@platform/core/concurrency';-import { apiFetch, apiFetchJson, apiFetchRaw, HttpRequestIdentityExpiredError } from '@platform/transport/http';+import { apiFetch, apiFetchJson, apiFetchRaw, assertOk, HttpRequestIdentityExpiredError } from '@platform/transport/http';/*** The asset half of a project file: pulling referenced bytes off the server on@@ -118,7 +118,16 @@ export const findExistingVideoNames = async (const found = await mapWithConcurrency(videoNames, VIDEO_EXISTENCE_CONCURRENCY, async (videoName) => {const response = await apiFetchRaw(`${VIDEOS_BASE}/i/${encodeURIComponent(videoName)}`, { signal });- return response.ok ? videoName : null;+ if (response.ok) {+ return videoName;+ }++ if (response.status === 403 || response.status === 404) {+ return null;+ }++ await assertOk(response);+ return null;});return new Set(found.filter((videoName): videoName is string => videoName !== null));