* feat(thumbnails): thumbnail format, quality and size as server settings
Thumbnail format (webp default, jxl, jpeg), quality (1-100, default 80)
and size limit (128-2048 px, default 512) are server settings in the
config.json thumbnails section, saved with the settings revision. The
never-read gallery thumbnail_size is gone: older saves wrote its unused
default 256 into config.json.
One module names previews (<stem>_thumb.webp/.jxl/.jpg) and finds the
preview a source owns, preferring the configured format; legacy names
are still found. The encoder module writes every preview atomically and
verifies it decodes. JPEG XL needs no new dependency: Pillow (natively
or with pillow_jxl), ffmpeg with libjxl, or cjxl; without one the
settings refuse jxl (400 jxl-unavailable) and GET says why. Encoder
processes are tracked, bounded and killed at shutdown.
* feat(thumbnails): every preview writer and lookup follows the thumbnail settings
Automatic previews (capture and first view), the thumbnail job, the
legacy gallery routes and the history route write <stem>_thumb.webp
(or .jxl/.jpg) with the configured quality and size limit, for images
and videos alike: video frames, ffmpeg's included (a PNG on stdout,
never upscaled), and the placeholder are encoded like images.
Listings, duplicates, enrichment, the autotag scan and the history
route show any preview the file owns, the current format first, so
older _thumb.png previews keep working until converted. A request for
an older name answers the current preview. Previews are served with
an explicit image/webp or image/jxl type and the same cache headers.
The plan and status count missing, outdated (another format) and
ready previews; the missing job never writes beside an outdated one.
Removing a file removes its previews in every format; the clear
removes .webp and .jxl too. Encoder processes are killed at shutdown.
A preview is only a placeholder: inspection refuses paths under
thumbnails/ and always reads the original, and the inspector cover
accepts the listing's preview in any format the file owns.
* feat(thumbnails): Convert outdated thumbnails as an Activity job
POST /jobs/thumbnails {mode: "convert"} starts "Convert outdated
thumbnails" under the thumbnail job's kind, guarded admission, worker
threads and cancel at a file boundary. For each file whose preview is
in another format, it writes the new preview from the source (atomic,
verified; a video with no decodable frame fails instead of getting the
placeholder), then removes that file's old-format previews in its
thumbnails folder. A failure keeps the old preview; orphan previews
and links are never touched. The final line reports converted, failed
and bytes before and after. The plan counts it with mode=convert; the
legacy gallery stream refuses to attach to a running conversion.
* feat(thumbnails): thumbnail settings in Appearance and Convert outdated in the workspace
System > Appearance gains a Thumbnails surface: format (WebP, JPEG XL,
JPEG), quality and size limit, saved to the server with the settings
revision. JPEG XL is offered only when the server has an encoder, else
the option is disabled with the server's reason (D130); a note says
when this browser cannot show JPEG XL. Saving a new format converts
nothing: the row then says previews keep their old format.
Thumbnail maintenance gains the Convert outdated scope and names the
server's settings instead of its own quality and size fields (D131).
Overview's thumbnail row reads N missing, M outdated, K failed and
offers Convert outdated while previews are outdated.
The workspace decodes a tiny JPEG XL once: where it cannot, cards, the
Library and the inspector cover load the original for a .jxl preview,
and any preview that fails to load falls back to the original. The
viewer and downloads keep using the original (regression test).
README explains enabling JPEG XL; TESTING.md records D130 and D131.
* test(thumbnails): coverage floors for the thumbnail modules and WebP in page workflows
The two new frontend modules enter the coverage baseline (98% lines);
other floors only rise. The visual fixture's preview is WebP and
Appearance has its Thumbnails surface in the System shell check.
* fix(thumbnails): say when the thumbnail settings could not be read
Like Appearance's other server rows, the Thumbnails rows show 'Server
settings could not be read.' while the read failed, instead of only
staying disabled. Firefox exposed the gap: its JPEG XL note arrived
first and changed the row notes the page workflow counted.
* test(thumbnails): accept the legacy preview's spelling a case-insensitive disk finds
On Windows and macOS the '.jpg' lookup finds an older release's
b_thumb.JPG first, so the listed URL spells '.jpg'; it names the same
file there. The test now accepts either spelling and checks the URL
serves that preview.
* fix(thumbnails): address the final review of the thumbnail format work
- ffmpeg writes JPEG XL with -update 1, so a % in a file name is never an
image-sequence pattern, and reads videos as file:<path>. The clear and a
startup sweep remove temp files that interrupted writes left behind.
- Convert outdated converts each group of same-stem files once, from the
first source in the R2 order. An old preview that is already gone counts
as removed, and each file's bytes count once. A current preview is only
kept if it decodes.
- An encoder that fails makes the write detect encoders again once. Another
encoder is used if one is found; with none, the file is written as WebP
and the availability Appearance shows is refreshed.
- Changing the thumbnail format, quality or size while Convert outdated runs
returns 409 busy. If the format still changes underneath, the job stops
without removing anything.
- Legacy preview spellings are matched case-insensitively, so X_thumb.JPG
counts as outdated.
- History's cover uses the same lookup as Images. It serves .jxl only when
Accept lists image/jxl, and otherwise the original or the placeholder.
- A video whose thumbnail the browser cannot show keeps its own element
(Images) or its label (Library).
* fix(thumbnails): keep the new preview, probe encoders only when gone, sweep reused PIDs
- Convert never removes a path that is the preview it just wrote. It
compares the device and inode, or the resolved and normcased paths when
the disk has no inode numbers. This covers x_thumb.JPG on a
case-insensitive disk.
- A JPEG XL encode failure re-runs encoder detection only when the
encoder's binary or module is gone. A "no encoder" result is checked
again on the settings read, on a jxl save, and after 60 s, so one slow
probe no longer turns JPEG XL off until a restart.
- The startup sweep now also removes temp files that carry this process's
PID but predate its start. Containers reuse PIDs.
* fix(history): let the cover ask for JPEG XL when this browser decodes it
Firefox can decode JPEG XL without listing image/jxl in Accept. When the
workspace's probe decodes JPEG XL, it adds jxl=1 to the History cover URL.
The server serves a .jxl preview when that flag is set or when Accept
lists image/jxl. In every other case it falls back as before. The flag
accepts only 0 or 1, and the response stays no-store.
* fix(thumbnails): keep going past the per-batch cap until every preview is made
The missing, rebuild and Convert outdated jobs stopped after
MAX_THUMBNAIL_FILES (10,000) files and said "N more on the next run", but
nothing ever started that next run. The cap now bounds one batch. After
each batch the job plans again, leaving out every file it already worked
on, and continues until nothing is left, the job is cancelled, or a batch
makes no progress. That last case stops on files that fail every time
instead of looping over them.
Activity progress counts against the overall total, and the final line and
the legacy stream's complete frame report every batch. Admission, worker
threads, cancellation and the #316 rules are unchanged. The Thumbnail
maintenance dialog now counts all the work instead of saying "more on the
next run".
171 lines
10 KiB
JavaScript
171 lines
10 KiB
JavaScript
import { startCoverage, saveCoverage } from '../../tools/vendor/browser-coverage.mjs';
|
|
import { test, expect } from './fixtures.mjs';
|
|
|
|
/**
|
|
* #249: cards and strips load previews, never the full file. The approved mock has no repeated thumbnail prompt
|
|
* (docs/concepts/workspace/README.md), so a preview that was not made yet is made by the server on first view:
|
|
* the listing still names the `_thumb` URL. Only the media viewer's main image (and downloads) load the original.
|
|
*/
|
|
const images = '/prompt_manager/workspace#/images';
|
|
const library = '/prompt_manager/workspace#/library';
|
|
const cards = page => page.locator('article[data-image-key]');
|
|
const details = page => page.getByRole('complementary', { name: 'Selected image details', exact: true });
|
|
const SERVE = '/prompt_manager/images/serve/';
|
|
|
|
/** Every media file the page asks the server for, as `{path, preview}` (path relative to its root). */
|
|
function recordMedia(page) {
|
|
const seen = [];
|
|
page.on('request', request => {
|
|
const url = new URL(request.url());
|
|
if (!url.pathname.startsWith(SERVE)) return;
|
|
const path = decodeURIComponent(url.pathname.slice(SERVE.length));
|
|
seen.push({ path, preview: /^thumbnails\/.+_thumb\.[a-z0-9]+$/.test(path) });
|
|
});
|
|
return seen;
|
|
}
|
|
/** Every card image has loaded (or failed): what it asked for is all in `seen`. */
|
|
const settled = page => page.evaluate(() => Promise.all([...document.querySelectorAll('article img')].map(image => image.decode().catch(() => {}))));
|
|
const originals = seen => seen.filter(item => !item.preview).map(item => item.path);
|
|
|
|
test.beforeEach(async ({ page, browserName }) => {
|
|
await startCoverage(page, browserName);
|
|
page.thumbErrors = [];
|
|
page.on('pageerror', error => page.thumbErrors.push(error.message));
|
|
});
|
|
test.afterEach(async ({ page, browserName }) => {
|
|
await saveCoverage(page, browserName);
|
|
expect(page.thumbErrors).toEqual([]);
|
|
});
|
|
|
|
test('a page of the Images grid requests previews, never originals, in every layout and size', async ({ page, request }) => {
|
|
await expect(await request.post('/__test__/reset')).toBeOK();
|
|
// Newest outputs with no preview yet: the live finding (844 such files listed with a null thumbnail).
|
|
await expect(await request.post('/__test__/system/unthumbnailed', { data: { count: 6 } })).toBeOK();
|
|
const listing = await (await request.get('/prompt_manager/images/output?limit=40')).json();
|
|
const fresh = listing.images.filter(image => image.path.startsWith('unthumbnailed/'));
|
|
expect(fresh).toHaveLength(6);
|
|
for (const image of fresh) expect(image.thumbnail_url).toMatch(/\/thumbnails\/unthumbnailed\/plain_\d{3}_thumb\.webp\?root=0/);
|
|
const seen = recordMedia(page);
|
|
await page.goto(images);
|
|
await expect(cards(page)).toHaveCount(8);
|
|
await settled(page);
|
|
expect(originals(seen)).toEqual([]);
|
|
expect(seen.filter(item => item.path.startsWith('thumbnails/unthumbnailed/'))).toHaveLength(6);
|
|
// The server made them on that first view.
|
|
await expect.poll(async () => (await (await request.get('/prompt_manager/images/thumbnails/status')).json()).pending).toBe(0);
|
|
for (const layout of ['List', 'Masonry', 'Grid']) {
|
|
await page.getByRole('button', { name: layout, exact: true }).click();
|
|
await expect(page.getByRole('button', { name: layout, exact: true })).toHaveAttribute('aria-pressed', 'true');
|
|
for (const density of ['large', 'compact', 'comfortable']) {
|
|
await page.getByRole('combobox', { name: 'Thumbnail size', exact: true }).selectOption(density);
|
|
await expect(cards(page)).toHaveCount(8);
|
|
await settled(page);
|
|
}
|
|
}
|
|
expect(originals(seen)).toEqual([]);
|
|
});
|
|
|
|
test('the inspector cover is the preview and only the media viewer loads the original', async ({ page, request }) => {
|
|
await expect(await request.post('/__test__/reset')).toBeOK();
|
|
await expect(await request.post('/__test__/system/unthumbnailed', { data: { count: 1 } })).toBeOK();
|
|
const seen = recordMedia(page);
|
|
await page.goto(images);
|
|
const card = cards(page).filter({ hasText: 'plain_001.png' });
|
|
await card.getByRole('button', { name: 'Inspect plain_001.png', exact: true }).click();
|
|
const cover = details(page).locator('img.detail-cover');
|
|
await expect(cover).toHaveAttribute('src', /\/thumbnails\/unthumbnailed\/plain_001_thumb\.webp\?/);
|
|
await settled(page);
|
|
await cover.evaluate(image => image.decode().catch(() => {}));
|
|
expect(originals(seen)).toEqual([]);
|
|
await card.getByRole('button', { name: 'Open plain_001.png', exact: true }).click();
|
|
await expect(page.locator('dialog#viewer-dialog')).toBeVisible();
|
|
await expect.poll(() => originals(seen)).toEqual(['unthumbnailed/plain_001.png']);
|
|
await page.getByRole('button', { name: 'Close image viewer', exact: true }).click();
|
|
});
|
|
|
|
test('a video card shows its preview frame instead of loading the video', async ({ page, request }) => {
|
|
await expect(await request.post('/__test__/reset', { data: { include_video: true } })).toBeOK();
|
|
const seen = recordMedia(page);
|
|
await page.goto(images);
|
|
const card = cards(page).filter({ hasText: 'clip.webm' });
|
|
await expect(card.locator('.media-art > .image-open > img')).toHaveAttribute('src', /\/thumbnails\/clip_thumb\.webp\?/);
|
|
await expect(card.locator('video')).toHaveCount(0);
|
|
await settled(page);
|
|
expect(originals(seen)).toEqual([]);
|
|
});
|
|
|
|
test('Library cards and the shared gallery request previews only', async ({ page, request }) => {
|
|
await expect(await request.post('/__test__/reset', { data: { native_library: true } })).toBeOK();
|
|
const seen = recordMedia(page);
|
|
await page.goto(library);
|
|
const cat = page.locator('article[data-prompt-id]').filter({ has: page.getByText('Cat portrait', { exact: true }) });
|
|
await expect(cat.locator('.card-art img')).not.toHaveCount(0);
|
|
await settled(page);
|
|
expect(seen.length).toBeGreaterThan(0);
|
|
expect(originals(seen)).toEqual([]);
|
|
});
|
|
|
|
test('a video whose preview cannot be loaded swaps back to its own element', async ({ page, request }) => {
|
|
await expect(await request.post('/__test__/reset', { data: { include_video: true } })).toBeOK();
|
|
await page.route(url => url.pathname.endsWith('/thumbnails/clip_thumb.webp'), route => route.fulfill({ status: 404, body: '' }));
|
|
await page.goto(images);
|
|
const card = cards(page).filter({ hasText: 'clip.webm' });
|
|
await expect(card.locator('.media-art > .image-open > video')).toHaveCount(1);
|
|
await expect(card.locator('.media-art > .image-open > img')).toHaveCount(0);
|
|
await card.getByRole('button', { name: 'Inspect clip.webm', exact: true }).click();
|
|
await expect(details(page).locator('video.detail-cover')).toHaveCount(1);
|
|
await expect(details(page).locator('img.detail-cover')).toHaveCount(0);
|
|
});
|
|
|
|
test('an image listed without a preview (a nested thumbnails folder) shows its original', async ({ page, request }) => {
|
|
await expect(await request.post('/__test__/reset')).toBeOK();
|
|
// M10: such files are listed with a null thumbnail_url; the card falls back to the original as before.
|
|
await page.route(url => url.pathname === '/prompt_manager/images/output', async route => {
|
|
const response = await route.fetch();
|
|
const body = await response.json();
|
|
if (Array.isArray(body.images)) body.images = body.images.map(image => ({ ...image, thumbnail_url: null }));
|
|
await route.fulfill({ response, json: body });
|
|
});
|
|
const seen = recordMedia(page);
|
|
await page.goto(images);
|
|
await expect(cards(page)).toHaveCount(2);
|
|
await settled(page);
|
|
expect(seen.length).toBeGreaterThan(0);
|
|
expect(seen.every(item => !item.preview)).toBe(true);
|
|
});
|
|
|
|
test('a JPEG XL thumbnail this browser cannot show loads the original; one it can show is used (#317)', async ({ page, request }) => {
|
|
await expect(await request.post('/__test__/reset')).toBeOK();
|
|
await expect(await request.post('/__test__/system/reset')).toBeOK();
|
|
try {
|
|
await expect(await request.post('/__test__/system/jxl-encoder', { data: { available: true } })).toBeOK();
|
|
const saved = await request.post('/prompt_manager/settings', { data: { thumbnail_format: 'jxl' } });
|
|
await expect(saved).toBeOK();
|
|
await expect(await request.post('/__test__/system/unthumbnailed', { data: { count: 1 } })).toBeOK();
|
|
const listing = await (await request.get('/prompt_manager/images/output?limit=40')).json();
|
|
const fresh = listing.images.find(image => image.path === 'unthumbnailed/plain_001.png');
|
|
expect(fresh.thumbnail_url).toMatch(/\/thumbnails\/unthumbnailed\/plain_001_thumb\.jxl\?root=0/);
|
|
await page.goto(images);
|
|
// What this browser does with JPEG XL, decided the way the workspace decides it (an embedded probe).
|
|
const decodes = await page.evaluate(() => new Promise(resolve => {
|
|
const probe = new Image();
|
|
probe.onload = () => resolve(true);
|
|
probe.onerror = () => resolve(false);
|
|
probe.src = 'data:image/jxl;base64,/woAkAEAE4gCALQAtZ8gAAAVKqOMG7yc6/nyQ4fFtI3rDG21bWEJY7O9MEhIOGwY4s3xwRCTShIA';
|
|
}));
|
|
const card = cards(page).filter({ hasText: 'plain_001.png' });
|
|
const media = card.locator('.media-art > .image-open > img');
|
|
// A browser without JPEG XL shows the original; one with it shows the preview, or the original when the
|
|
// preview cannot be made here (no real encoder in the test server): never a broken image.
|
|
if (!decodes) await expect(media).toHaveAttribute('src', /\/unthumbnailed\/plain_001\.png\?root=0/);
|
|
await expect.poll(() => media.evaluate(image => image.complete && image.naturalWidth > 0)).toBe(true);
|
|
// The inspector cover follows the same rule.
|
|
await card.getByRole('button', { name: 'Inspect plain_001.png', exact: true }).click();
|
|
const cover = details(page).locator('img.detail-cover');
|
|
if (!decodes) await expect(cover).toHaveAttribute('src', /\/unthumbnailed\/plain_001\.png\?/);
|
|
await expect.poll(() => cover.evaluate(image => image.complete && image.naturalWidth > 0)).toBe(true);
|
|
} finally {
|
|
await request.post('/__test__/system/reset');
|
|
}
|
|
});
|