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>
53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
/**
|
|
* Rebuilds stored raw proxies from their originals.
|
|
*
|
|
* A decode is CPU bound and holds a LibRaw worker for seconds, so the work runs
|
|
* one photo at a time behind a snapshot: a request that blocked for an hour
|
|
* would time out, and decoding in parallel would starve the editor. Progress
|
|
* lives in memory only, so an interrupted rebuild simply starts again.
|
|
*/
|
|
|
|
/** Photos that have a proxy worth regenerating: camera raws that still exist. */
|
|
export function previewRebuildTargets(photos) {
|
|
return photos.filter((photo) => photo && photo.raw === true && !photo.deletedAt);
|
|
}
|
|
|
|
/**
|
|
* Runs `regenerate(photo)` for every target and reports progress.
|
|
*
|
|
* A photo that fails is counted and recorded, and the run continues: one
|
|
* unreadable original must not strand the rest of the library.
|
|
*/
|
|
export function startPreviewRebuild({ targets, regenerate, now = Date.now }) {
|
|
const job = {
|
|
state: 'running',
|
|
total: targets.length,
|
|
done: 0,
|
|
failed: 0,
|
|
sidecars: 0,
|
|
startedAt: now(),
|
|
finishedAt: null,
|
|
errors: [],
|
|
};
|
|
|
|
const finished = (async () => {
|
|
for (const photo of targets) {
|
|
try {
|
|
const result = await regenerate(photo);
|
|
if (result?.sidecar) job.sidecars += 1;
|
|
} catch (err) {
|
|
job.failed += 1;
|
|
if (job.errors.length < 5) {
|
|
const label = photo?.name || photo?.id || 'photo';
|
|
job.errors.push(`${label}: ${err instanceof Error ? err.message : String(err)}`);
|
|
}
|
|
}
|
|
job.done += 1;
|
|
}
|
|
job.state = 'done';
|
|
job.finishedAt = now();
|
|
})();
|
|
|
|
return { snapshot: () => ({ ...job, errors: [...job.errors] }), finished };
|
|
}
|