158dccddf1
A library imported by an older pipeline keeps whatever proxy it was given, and the editor can only show those bytes. The Storage tab now re-decodes every camera raw from its original, writing a fresh JPEG proxy, thumbnail, 16-bit sidecar and denoise prune, then stamps previewVersion so browsers refetch. The decode loop runs one photo at a time on the server behind a status route: an hour of LibRaw work would time out as a request, and parallel decodes would starve the editor. The single-photo reprocess route shares the same helper. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
72 lines
2.4 KiB
JavaScript
72 lines
2.4 KiB
JavaScript
import { describe, expect, it } from 'vitest';
|
|
import { previewRebuildTargets, startPreviewRebuild } from './previewRebuild.mjs';
|
|
|
|
describe('preview rebuild targets', () => {
|
|
it('takes live camera raws and nothing else', () => {
|
|
const photos = [
|
|
{ id: 'raw', raw: true },
|
|
{ id: 'jpeg', raw: false },
|
|
{ id: 'trashed', raw: true, deletedAt: 1 },
|
|
{ id: 'unknown' },
|
|
];
|
|
expect(previewRebuildTargets(photos).map((photo) => photo.id)).toEqual(['raw']);
|
|
});
|
|
});
|
|
|
|
describe('preview rebuild job', () => {
|
|
it('walks every target in order and counts the 16-bit sidecars', async () => {
|
|
const seen = [];
|
|
const job = startPreviewRebuild({
|
|
targets: [{ id: 'a' }, { id: 'b' }],
|
|
regenerate: async (photo) => {
|
|
seen.push(photo.id);
|
|
return { sidecar: photo.id === 'a' };
|
|
},
|
|
now: () => 7,
|
|
});
|
|
expect(job.snapshot()).toMatchObject({ state: 'running', total: 2, done: 0 });
|
|
await job.finished;
|
|
expect(seen).toEqual(['a', 'b']);
|
|
expect(job.snapshot()).toMatchObject({
|
|
state: 'done',
|
|
done: 2,
|
|
failed: 0,
|
|
sidecars: 1,
|
|
startedAt: 7,
|
|
finishedAt: 7,
|
|
});
|
|
});
|
|
|
|
it('keeps going after a photo that cannot be decoded', async () => {
|
|
const job = startPreviewRebuild({
|
|
targets: [{ id: 'a', name: 'A.CR2' }, { id: 'b', name: 'B.CR2' }],
|
|
regenerate: async (photo) => {
|
|
if (photo.id === 'a') throw new Error('the original is missing');
|
|
return { sidecar: false };
|
|
},
|
|
});
|
|
await job.finished;
|
|
const snapshot = job.snapshot();
|
|
expect(snapshot).toMatchObject({ state: 'done', done: 2, failed: 1, sidecars: 0 });
|
|
expect(snapshot.errors[0]).toContain('A.CR2');
|
|
expect(snapshot.errors[0]).toContain('the original is missing');
|
|
});
|
|
|
|
it('hands out copies, so a caller cannot edit the live progress', async () => {
|
|
const job = startPreviewRebuild({
|
|
targets: [{ id: 'a' }],
|
|
regenerate: async () => ({ sidecar: false }),
|
|
});
|
|
const snapshot = job.snapshot();
|
|
snapshot.errors.push('tampered');
|
|
await job.finished;
|
|
expect(job.snapshot().errors).toEqual([]);
|
|
});
|
|
|
|
it('finishes immediately when there is nothing to rebuild', async () => {
|
|
const job = startPreviewRebuild({ targets: [], regenerate: async () => ({ sidecar: false }) });
|
|
await job.finished;
|
|
expect(job.snapshot()).toMatchObject({ state: 'done', total: 0, done: 0, failed: 0 });
|
|
});
|
|
});
|