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
feat(webv2): surface board video counts and partial delete failures
joshistoastdd2b10a16d5e
diff --git a/invokeai/frontend/webv2/src/features/gallery/core/types.ts b/invokeai/frontend/webv2/src/features/gallery/core/types.tsindex 634291c887..702bcfc35c 100644--- a/invokeai/frontend/webv2/src/features/gallery/core/types.ts+++ b/invokeai/frontend/webv2/src/features/gallery/core/types.ts@@ -22,8 +22,12 @@ export interface GalleryBoard {kind: GalleryBoardKind;imageCount: number;assetCount: number;+ /** Videos on the board, counted separately from `imageCount` by the backend. */+ videoCount: number;archived: boolean;coverImageName?: string | null;+ /** Set instead of `coverImageName` when the board's most recent item is a video. */+ coverVideoName?: string | null;coverThumbnailUrl?: string;/** ISO creation timestamp; absent for uncategorized and date virtual boards. */createdAt?: string | null;@@ -38,6 +42,15 @@ export interface GalleryImage extends GeneratedImageContract {export type GalleryImageMetadata = Record<string, unknown>;+/**+ * Per-name outcome of a bulk delete. The backend deletes each name independently, so a+ * request can partly succeed and callers must evict only what actually went away.+ */+export interface GalleryDeletionResult {+ deletedImageNames: string[];+ failedImageNames: string[];+}+export interface GalleryImagesPage {images: GalleryImage[];total: number;diff --git a/invokeai/frontend/webv2/src/features/gallery/core/videoPaths.ts b/invokeai/frontend/webv2/src/features/gallery/core/videoPaths.tsnew file mode 100644index 0000000000..dd610c9807--- /dev/null+++ b/invokeai/frontend/webv2/src/features/gallery/core/videoPaths.ts@@ -0,0 +1,13 @@+/**+ * Backend-relative video media paths, mirroring {@link ./imagePaths}.+ *+ * Both routes authenticate with the path-scoped media cookie rather than a bearer header,+ * because `<video>` and `<img>` cannot set request headers. The full route additionally+ * serves HTTP Range requests, which the `<video>` element issues on its own for seeking.+ */++export const getGalleryVideoThumbnailPath = (videoName: string): string =>+ `/api/v1/videos/i/${encodeURIComponent(videoName)}/thumbnail`;++export const getGalleryVideoFullPath = (videoName: string): string =>+ `/api/v1/videos/i/${encodeURIComponent(videoName)}/full`;diff --git a/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts b/invokeai/frontend/webv2/src/features/gallery/data/backend.test.tsindex 33c118ff0a..0920f26bc3 100644--- a/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts+++ b/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts@@ -16,12 +16,14 @@ vi.mock('@platform/transport/http', () => ({}));import {+ deleteGalleryImages,downloadGalleryArchive,getGalleryImageByName,getGalleryImagesByNames,imageMakeCanvasAssetChanges,imageMakeDurableChanges,imageSaveToGalleryChanges,+ listGalleryBoards,listGalleryImages,} from './backend';@@ -295,3 +297,120 @@ describe('gallery category queries', () => {expect([...assets, ...images]).not.toContain('other');});});++describe('board media counts and covers', () => {+ beforeEach(() => {+ accountLifecycle.activate('user-a');+ mocks.apiFetchJson.mockReset();+ });++ it('maps video counts and resolves a video cover to its thumbnail', async () => {+ mocks.apiFetchJson.mockImplementation((path: string) => {+ if (path.startsWith('/api/v1/boards/')) {+ return Promise.resolve([+ {+ archived: false,+ asset_count: 1,+ board_id: 'board-1',+ board_name: 'Clips',+ cover_image_name: null,+ cover_video_name: 'clip.mp4',+ image_count: 2,+ video_count: 3,+ },+ ]);+ }++ // Uncategorized image / asset / video totals.+ return Promise.resolve({ total: 0 });+ });++ const boards = await listGalleryBoards();++ expect(boards[1]).toMatchObject({+ coverThumbnailUrl: 'https://api.test/api/v1/videos/i/clip.mp4/thumbnail',+ coverVideoName: 'clip.mp4',+ id: 'board-1',+ imageCount: 2,+ videoCount: 3,+ });+ });++ it('counts uncategorized videos, which no board DTO reports', async () => {+ mocks.apiFetchJson.mockImplementation((path: string) => {+ if (path.startsWith('/api/v1/boards/')) {+ return Promise.resolve([]);+ }++ if (path.startsWith('/api/v1/videos/')) {+ return Promise.resolve({ total: 7 });+ }++ return Promise.resolve({ total: 4 });+ });++ const boards = await listGalleryBoards();++ expect(boards[0]).toMatchObject({ id: 'none', kind: 'uncategorized', videoCount: 7 });+ });++ it('treats a board with only videos as non-empty even though image_count is 0', async () => {+ mocks.apiFetchJson.mockImplementation((path: string) => {+ if (path.startsWith('/api/v1/boards/')) {+ return Promise.resolve([+ {+ archived: false,+ asset_count: 0,+ board_id: 'video-only',+ board_name: 'Video only',+ cover_image_name: null,+ cover_video_name: 'only.mp4',+ image_count: 0,+ video_count: 5,+ },+ ]);+ }++ return Promise.resolve({ total: 0 });+ });++ const boards = await listGalleryBoards();++ expect(boards[1]).toMatchObject({ imageCount: 0, videoCount: 5 });+ expect(boards[1]?.coverThumbnailUrl).toBeDefined();+ });+});++describe('deleteGalleryImages partial failures', () => {+ beforeEach(() => {+ accountLifecycle.activate('user-a');+ mocks.apiFetchJson.mockReset();+ });++ it('separates deleted names from ones the backend refused', async () => {+ mocks.apiFetchJson.mockResolvedValue({+ affected_boards: ['board-1'],+ deleted_images: ['gone.png'],+ failed_images: ['locked.png'],+ });++ await expect(deleteGalleryImages(['gone.png', 'locked.png'])).resolves.toEqual({+ deletedImageNames: ['gone.png'],+ failedImageNames: ['locked.png'],+ });+ });++ it('reports no failures when the backend omits failed_images', async () => {+ mocks.apiFetchJson.mockResolvedValue({ affected_boards: [], deleted_images: ['gone.png'] });++ await expect(deleteGalleryImages(['gone.png'])).resolves.toEqual({+ deletedImageNames: ['gone.png'],+ failedImageNames: [],+ });+ });++ it('skips the request entirely for an empty selection', async () => {+ await expect(deleteGalleryImages([])).resolves.toEqual({ deletedImageNames: [], failedImageNames: [] });+ expect(mocks.apiFetchJson).not.toHaveBeenCalled();+ });+});diff --git a/invokeai/frontend/webv2/src/features/gallery/data/backend.ts b/invokeai/frontend/webv2/src/features/gallery/data/backend.tsindex 2284158fbb..0ba9629e6d 100644--- a/invokeai/frontend/webv2/src/features/gallery/data/backend.ts+++ b/invokeai/frontend/webv2/src/features/gallery/data/backend.ts@@ -1,6 +1,7 @@import type {GalleryBoard,GalleryBoardOrderBy,+ GalleryDeletionResult,GalleryImage,GalleryImageMetadata,GalleryImagesPage,@@ -13,14 +14,19 @@ import { assertAccountScopeCurrent, captureAccountScope } from '@platform/state/import { absolutizeApiUrl, apiFetch, apiFetchJson, apiFetchRaw, sleep } from '@platform/transport/http';import { getGalleryImageThumbnailUrl } from './imageUrls';+import { getGalleryVideoThumbnailUrl } from './videoUrls';interface BackendBoardDTO {board_id: string;board_name: string;image_count: number;asset_count: number;+ /** Videos on the board. Counted separately from `image_count` by the backend. */+ video_count?: number;archived: boolean;cover_image_name?: string | null;+ /** Set instead of `cover_image_name` when the board's most recent item is a video. */+ cover_video_name?: string | null;created_at?: string | null;/** Board owner's display name; populated only for admins on multi-user backends. */owner_username?: string | null;@@ -88,17 +94,34 @@ const toSearchParams = (entries: Record<string, boolean | number | string | strireturn params.toString();};+/**+ * The backend sets exactly one of `cover_image_name` / `cover_video_name`, depending on which+ * kind the board's most recent item is. Both resolve to a static WebP thumbnail, so the cover+ * renders identically either way.+ */+const getBoardCoverThumbnailUrl = (+ board: Pick<BackendBoardDTO, 'cover_image_name' | 'cover_video_name'>+): string | undefined => {+ if (board.cover_image_name) {+ return getGalleryImageThumbnailUrl(board.cover_image_name);+ }++ return board.cover_video_name ? getGalleryVideoThumbnailUrl(board.cover_video_name) : undefined;+};+const mapBoard = (board: BackendBoardDTO): GalleryBoard => ({archived: board.archived,assetCount: board.asset_count,coverImageName: board.cover_image_name,- coverThumbnailUrl: board.cover_image_name ? getGalleryImageThumbnailUrl(board.cover_image_name) : undefined,+ coverThumbnailUrl: getBoardCoverThumbnailUrl(board),+ coverVideoName: board.cover_video_name,createdAt: board.created_at ?? null,id: board.board_id,imageCount: board.image_count,kind: 'board',name: board.board_name,ownerName: board.owner_username ?? null,+ videoCount: board.video_count ?? 0,});const getGalleryTotal = async ({@@ -122,6 +145,23 @@ const getGalleryTotal = async ({return body.total;};+/**+ * Videos carry no category split — the gallery's Images/Assets views are an image-only+ * distinction — so this counts every non-intermediate video on the board.+ */+const getGalleryVideoTotal = async ({+ boardId,+ signal,+}: {+ boardId: string;+ signal?: AbortSignal;+}): Promise<number> => {+ const query = toSearchParams({ board_id: boardId, is_intermediate: false, limit: 0, offset: 0 });+ const body = await apiFetchJson<{ total: number }>(`/api/v1/videos/?${query}`, { signal });++ return body.total;+};+const mapImage = (image: BackendImageDTO): GalleryImage => ({boardId: image.board_id ?? 'none',height: image.height,@@ -160,10 +200,13 @@ export const listGalleryBoards = async ({{ signal });- const [body, uncategorizedImageCount, uncategorizedAssetCount] = await Promise.all([+ const [body, uncategorizedImageCount, uncategorizedAssetCount, uncategorizedVideoCount] = await Promise.all([boardsBodyPromise,getGalleryTotal({ boardId: 'none', categories: imageCategories, signal }),getGalleryTotal({ boardId: 'none', categories: assetCategories, signal }),+ // Real boards carry `video_count` in their DTO, but the uncategorized pseudo-board is+ // assembled here, so its video total needs its own request.+ getGalleryVideoTotal({ boardId: 'none', signal }),]);const boards = Array.isArray(body) ? body : (body.items ?? []);@@ -175,18 +218,25 @@ export const listGalleryBoards = async ({imageCount: uncategorizedImageCount,kind: 'uncategorized',name: 'Uncategorized',+ videoCount: uncategorizedVideoCount,},...boards.filter((board) => includeArchived || !board.archived).map(mapBoard),];};+/**+ * Date boards are now derived from the polymorphic gallery service, so a date can exist+ * because of videos alone — its `image_count` may be 0 while the board is non-empty.+ */interface VirtualDateBoardDTO {virtual_board_id: string;board_name: string;date: string;image_count: number;asset_count: number;+ video_count?: number;cover_image_name?: string | null;+ cover_video_name?: string | null;}export const listGalleryDateBoards = async (signal?: AbortSignal): Promise<GalleryBoard[]> => {@@ -196,11 +246,13 @@ export const listGalleryDateBoards = async (signal?: AbortSignal): Promise<Gallearchived: false,assetCount: board.asset_count,coverImageName: board.cover_image_name,- coverThumbnailUrl: board.cover_image_name ? getGalleryImageThumbnailUrl(board.cover_image_name) : undefined,+ coverThumbnailUrl: getBoardCoverThumbnailUrl(board),+ coverVideoName: board.cover_video_name,id: board.virtual_board_id,imageCount: board.image_count,kind: 'date',name: board.board_name,+ videoCount: board.video_count ?? 0,}));};@@ -536,16 +588,39 @@ export const starGalleryImages = (imageNames: string[], signal?: AbortSignal): Pexport const unstarGalleryImages = (imageNames: string[], signal?: AbortSignal): Promise<void> =>setGalleryImagesStarred(imageNames, false, signal);-export const deleteGalleryImages = async (imageNames: string[], signal?: AbortSignal): Promise<void> => {+interface DeleteImagesResponse {+ deleted_images: string[];+ /** Names the backend could not delete. Absent on backends predating partial-failure reporting. */+ failed_images?: string[];+ affected_boards: string[];+}++/**+ * Deletes images and reports the outcome per name.+ *+ * The backend deletes each name independently and no longer aborts the batch on the first+ * failure, so a request can partly succeed. Callers must evict only `deletedImageNames` from+ * their caches — treating the whole request as successful would hide a still-present image+ * until the next full refresh.+ */+export const deleteGalleryImages = async (+ imageNames: string[],+ signal?: AbortSignal+): Promise<GalleryDeletionResult> => {if (imageNames.length === 0) {- return;+ return { deletedImageNames: [], failedImageNames: [] };}- await apiFetchJson('/api/v1/images/delete', {+ const body = await apiFetchJson<DeleteImagesResponse>('/api/v1/images/delete', {body: JSON.stringify({ image_names: imageNames }),method: 'POST',signal,});++ return {+ deletedImageNames: body.deleted_images,+ failedImageNames: body.failed_images ?? [],+ };};const BULK_DOWNLOAD_POLL_INTERVAL_MS = 2000;diff --git a/invokeai/frontend/webv2/src/features/gallery/data/videoUrls.ts b/invokeai/frontend/webv2/src/features/gallery/data/videoUrls.tsnew file mode 100644index 0000000000..b2d692bdd3--- /dev/null+++ b/invokeai/frontend/webv2/src/features/gallery/data/videoUrls.ts@@ -0,0 +1,8 @@+import { getGalleryVideoFullPath, getGalleryVideoThumbnailPath } from '@features/gallery/core/videoPaths';+import { absolutizeApiUrl } from '@platform/transport/http';++export const getGalleryVideoThumbnailUrl = (videoName: string): string =>+ absolutizeApiUrl(getGalleryVideoThumbnailPath(videoName));++export const getGalleryVideoFullUrl = (videoName: string): string =>+ absolutizeApiUrl(getGalleryVideoFullPath(videoName));diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/galleryStateView.test.ts b/invokeai/frontend/webv2/src/features/gallery/ui/galleryStateView.test.tsindex 804fffc1c4..cb7a81e38d 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/galleryStateView.test.ts+++ b/invokeai/frontend/webv2/src/features/gallery/ui/galleryStateView.test.ts@@ -13,8 +13,16 @@ import {} from './galleryStateView';const boards: GalleryBoard[] = [- { archived: false, assetCount: 0, id: 'none', imageCount: 1, kind: 'uncategorized', name: 'Uncategorized' },- { archived: false, assetCount: 0, id: 'board-1', imageCount: 2, kind: 'board', name: 'Board 1' },+ {+ archived: false,+ assetCount: 0,+ id: 'none',+ imageCount: 1,+ kind: 'uncategorized',+ name: 'Uncategorized',+ videoCount: 0,+ },+ { archived: false, assetCount: 0, id: 'board-1', imageCount: 2, kind: 'board', name: 'Board 1', videoCount: 0 },];const createImage = (imageName: string): GeneratedImageContract => ({diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/galleryStateView.ts b/invokeai/frontend/webv2/src/features/gallery/ui/galleryStateView.tsindex 708f99ea9e..0dbc50a7d8 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/galleryStateView.ts+++ b/invokeai/frontend/webv2/src/features/gallery/ui/galleryStateView.ts@@ -19,6 +19,7 @@ const UNCATEGORIZED_BOARD: GalleryBoard = {imageCount: 0,kind: 'uncategorized',name: 'Uncategorized',+ videoCount: 0,};/**diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts b/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.tsindex 102c17cbca..8577b6285c 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts@@ -159,13 +159,34 @@ export const useImageActions = ({const owner = captureAccountScope();try {- await galleryOrganization.deleteImages(imageNames, owner.signal);+ const { deletedImageNames, failedImageNames } = await galleryOrganization.deleteImages(+ imageNames,+ owner.signal+ );assertAccountScopeCurrent(owner);- patchGalleryImageCaches(queryClient, { imageNames, kind: 'delete' });- gallery.removeImages(imageNames);- onImagesDeleted?.(imageNames);- recordSuccess(imageNames.length === 1 ? 'Deleted image' : `Deleted ${imageNames.length} images`);+ // Evict only what the backend actually deleted. A name it refused is still on the+ // server, so dropping it from the cache would hide a live image until a full refresh.+ if (deletedImageNames.length > 0) {+ patchGalleryImageCaches(queryClient, { imageNames: deletedImageNames, kind: 'delete' });+ gallery.removeImages(deletedImageNames);+ onImagesDeleted?.(deletedImageNames);+ }++ if (failedImageNames.length > 0) {+ recordError(+ new Error(+ failedImageNames.length === 1+ ? `Could not delete ${failedImageNames[0]}`+ : `Could not delete ${failedImageNames.length} of ${imageNames.length} images`+ )+ );+ } else {+ recordSuccess(+ deletedImageNames.length === 1 ? 'Deleted image' : `Deleted ${deletedImageNames.length} images`+ );+ }+void invalidateGallery(queryClient);} catch (error: unknown) {if (!isAccountScopeCurrent(owner)) {diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsxindex 4a90fc4ceb..9fbf494682 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx@@ -76,7 +76,15 @@ type PreviewImage = GeneratedImageContract & Partial<Pick<GalleryImage, 'boardIdconst EMPTY_PREVIEW_IMAGES: PreviewImage[] = [];const fallbackBoards: GalleryBoard[] = [- { archived: false, assetCount: 0, id: 'none', imageCount: 0, kind: 'uncategorized', name: 'Uncategorized' },+ {+ archived: false,+ assetCount: 0,+ id: 'none',+ imageCount: 0,+ kind: 'uncategorized',+ name: 'Uncategorized',+ videoCount: 0,+ },];const getGalleryImages = (values: Record<string, unknown>, queueItems: QueueItem[]): PreviewImage[] => {