The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(civitai): load a small still as the search preview, never the original video
purplefaaffb6b0bdf
diff --git a/src/api/__tests__/a-civitai-preview-is-a-small-still.test.ts b/src/api/__tests__/a-civitai-preview-is-a-small-still.test.tsnew file mode 100644index 00000000..a74c19c4--- /dev/null+++ b/src/api/__tests__/a-civitai-preview-is-a-small-still.test.ts@@ -0,0 +1,83 @@+/**+ * Discord #bug-reports, 29.10.2026 (Ubuntu): "when searching for models in app+ * from civitai searchbox, the app crashes".+ *+ * The search put the first image of each hit into an `<img>` as CivitAI names+ * it: the original file. Measured for "wan", 20 hits with 19 previews: 13 were MP4 videos, 68 MB+ * together (the largest 15.9 MB), for 56 px cards. WebKitGTK decodes a video in+ * an `<img>` with GStreamer, so Linux ran up to twenty video decoders per+ * search. The CDN's `anim=false` gives one JPEG frame of the same file instead+ * (measured: image/jpeg, 111 KB; all 19 together 1.89 MB).+ *+ * Run: npx vitest run src/api/__tests__/a-civitai-preview-is-a-small-still.test.ts+ */+import { describe, it, expect, beforeEach, vi } from 'vitest'++const fetchExternal = vi.fn()+vi.mock('../backend', () => ({+ backendCall: vi.fn(),+ fetchExternal: (...args: unknown[]) => fetchExternal(...args),+ isTauri: () => true,+ isMacOS: () => false,+ secretGet: vi.fn().mockRejectedValue(new Error('no keychain here')),+ secretSet: vi.fn(),+ secretDelete: vi.fn(),+}))++import { searchCivitaiModels, civitaiThumbUrl } from '../discover'++// The shape of the real answer for "wan" (29.10.2026), shortened to two hits.+const VIDEO = 'https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/aea4631f-3ca2-4641-9cb3-7509ab47e97a/original=true/94287650.mp4'+const IMAGE = 'https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/9fd7e6dd-f91f-44b8-b2b2-12a1dbf30515/original=true/72289903.jpeg'+const answer = JSON.stringify({+ items: [+ { id: 1, name: 'Wan Video 2.2', stats: {}, modelVersions: [{ images: [{ type: 'video', url: VIDEO }], files: [{ name: 'a.safetensors', sizeKB: 1 }] }] },+ { id: 2, name: 'Wan Video 2.1', stats: {}, modelVersions: [{ images: [{ type: 'image', url: IMAGE }], files: [{ name: 'b.safetensors', sizeKB: 1 }] }] },+ ],+})++beforeEach(() => {+ fetchExternal.mockReset()+ fetchExternal.mockResolvedValue(answer)+})++describe('the preview of a CivitAI hit', () => {+ it('is never the original file', async () => {+ const hits = await searchCivitaiModels('wan')+ for (const h of hits) expect(h.thumbnailUrl).not.toContain('original=true')+ })++ it('asks the CDN for a still frame of a video, not for the video', async () => {+ const [video] = await searchCivitaiModels('wan')+ expect(video.thumbnailUrl).toBe(+ 'https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/aea4631f-3ca2-4641-9cb3-7509ab47e97a/anim=false,width=450,optimized=true/94287650.mp4')+ })++ it('asks for a small rendition of an image', async () => {+ const [, image] = await searchCivitaiModels('wan')+ expect(image.thumbnailUrl).toBe(+ 'https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/9fd7e6dd-f91f-44b8-b2b2-12a1dbf30515/anim=false,width=450,optimized=true/72289903.jpeg')+ })+})++describe('civitaiThumbUrl', () => {+ it('fills in the settings part an older answer leaves out', () => {+ expect(civitaiThumbUrl('https://image.civitai.com/k/u/1.jpeg', 'image'))+ .toBe('https://image.civitai.com/k/u/anim=false,width=450,optimized=true/1.jpeg')+ })++ it('gives a video on any other host no preview at all', () => {+ expect(civitaiThumbUrl('https://example.test/clip.mp4', 'video')).toBeUndefined()+ expect(civitaiThumbUrl('https://example.test/clip.webm')).toBeUndefined()+ })++ // Negative controls: what is not a video on the CDN stays as it was.+ it('leaves an image on another host as it is', () => {+ expect(civitaiThumbUrl('https://example.test/a.png', 'image')).toBe('https://example.test/a.png')+ })++ it('has nothing to show for no address or a broken one', () => {+ expect(civitaiThumbUrl(undefined)).toBeUndefined()+ expect(civitaiThumbUrl('not a url', 'image')).toBeUndefined()+ })+})diff --git a/src/api/discover.ts b/src/api/discover.tsindex 43a3539f..e6f6cd8a 100644--- a/src/api/discover.ts+++ b/src/api/discover.ts@@ -2125,6 +2125,48 @@ export function civitaiHostSwap(url: string | undefined, host: string): string |return url.replace(/^(https?:\/\/)civitai\.com/i, `$1${host}`)}+/**+ * Das Vorschaubild eines CivitAI-Treffers als kleines Standbild.+ *+ * Discord #bug-reports, 29.10.2026 (Ubuntu): „when searching for models in app+ * from civitai searchbox, the app crashes". Die API nennt als erstes Bild einer+ * Version die Originaldatei (`…/original=true/123.mp4`). Gemessen für „wan“,+ * 20 Treffer mit 19 Vorschaubildern: 13 davon MP4-Videos, zusammen 68 MB (das größte 15,9 MB) für+ * Kärtchen von 56 px. Auf Linux dekodiert WebKitGTK ein Video im `<img>` mit+ * GStreamer (WebView2 unter Windows zeigt es gar nicht), also+ * zwanzig Videodekoder auf einmal, mit echter GPU über VA-API/GL.+ *+ * Der Bild-CDN von CivitAI liefert dieselbe Datei verkleinert, und mit+ * `anim=false` auch ein Video als einzelnes JPEG (gemessen: 111 KB statt+ * 695 KB bis 16 MB, image/jpeg statt video/mp4; alle 19 zusammen+ * 1,89 MB). Dieselbe Angabe benutzt die CivitAI-Seite selbst. Ein Video, das+ * nicht auf diesem CDN liegt, bekommt KEIN Vorschaubild: ein Video gehört nicht+ * in ein `<img>`.+ */+const CIVITAI_THUMB_PARAMS = 'anim=false,width=450,optimized=true'++export function civitaiThumbUrl(url: string | undefined, type?: string): string | undefined {+ if (!url) return undefined+ const isVideo = type === 'video' || /\.(mp4|webm|mov|m4v)(\?|#|$)/i.test(url)+ let parsed: URL+ try {+ parsed = new URL(url)+ } catch {+ return undefined+ }+ if (parsed.protocol !== 'https:' || parsed.hostname !== 'image.civitai.com') {+ return isVideo ? undefined : url+ }+ // /<Schlüssel>/<uuid>/<Angaben>/<Name>, ältere Antworten ohne Angaben-Teil.+ const segs = parsed.pathname.split('/').filter(Boolean)+ if (segs.length === 4 && segs[2].includes('=')) segs[2] = CIVITAI_THUMB_PARAMS+ else if (segs.length === 3) segs.splice(2, 0, CIVITAI_THUMB_PARAMS)+ else return isVideo ? undefined : url+ // `pathname` ist schon kodiert, die Teile gehen unverändert zurück.+ parsed.pathname = '/' + segs.join('/')+ return parsed.toString()+}+/*** Eine CivitAI-Beschreibung als Text, nicht als Markup.*@@ -2285,7 +2327,8 @@ export async function searchCivitaiModels(const version = asRecordArray(prop(item, 'modelVersions'))[0]const files = asRecordArray(prop(version, 'files'))const file = only?.safetensorsOnly ? files.find(isSafetensors) : files[0]- const thumb = asString(propPath(asRecordArray(prop(version, 'images'))[0], 'url'))+ const firstImage = asRecordArray(prop(version, 'images'))[0]+ const thumb = civitaiThumbUrl(asString(prop(firstImage, 'url')), asString(prop(firstImage, 'type')))// The version's own address is that of its first file. Where a later// file was picked, only that file's address fetches it.const downloadUrl = only?.safetensorsOnly