Add an admin action that rebuilds preview proxies
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>
This commit is contained in:
@@ -6,6 +6,7 @@ import type {
|
||||
AdminUser,
|
||||
CatalogBackup,
|
||||
MailStatus,
|
||||
PreviewRebuildStatus,
|
||||
SessionUser,
|
||||
StorageChange,
|
||||
} from '../lib/api';
|
||||
@@ -19,6 +20,8 @@ import {
|
||||
adminRestoreCatalog,
|
||||
adminRevokeInvite,
|
||||
adminOverview,
|
||||
adminPreviewRebuildStatus,
|
||||
adminRebuildPreviews,
|
||||
adminRenameEvent,
|
||||
adminSaveImmich,
|
||||
adminSaveMail,
|
||||
@@ -73,6 +76,18 @@ const planSummary = (quota: AdminQuota) => {
|
||||
|
||||
type Tab = 'users' | 'invites' | 'content' | 'storage' | 'quotas' | 'immich' | 'backup';
|
||||
|
||||
/** No rebuild has run in this process yet. */
|
||||
const idleRebuild: PreviewRebuildStatus = {
|
||||
state: 'idle',
|
||||
total: 0,
|
||||
done: 0,
|
||||
failed: 0,
|
||||
sidecars: 0,
|
||||
startedAt: null,
|
||||
finishedAt: null,
|
||||
errors: [],
|
||||
};
|
||||
|
||||
const inviteUrl = (token: string) => `${window.location.origin}/join/${token}`;
|
||||
|
||||
const inviteStatusLabel: Record<AdminInvite['status'], string> = {
|
||||
@@ -109,6 +124,8 @@ export default function AdminPanel({ user, onClose, onChanged, onRestored }: Pro
|
||||
|
||||
const [rootInput, setRootInput] = useState('');
|
||||
const [change, setChange] = useState<StorageChange | null>(null);
|
||||
const [rebuild, setRebuild] = useState<PreviewRebuildStatus>(idleRebuild);
|
||||
const [rebuildBusy, setRebuildBusy] = useState(false);
|
||||
const restoreInput = useRef<HTMLInputElement>(null);
|
||||
const [restoreNote, setRestoreNote] = useState<string | null>(null);
|
||||
|
||||
@@ -117,6 +134,51 @@ export default function AdminPanel({ user, onClose, onChanged, onRestored }: Pro
|
||||
const [mail, setMail] = useState<MailStatus | null>(null);
|
||||
const [immichDraft, setImmichDraft] = useState({ url: '', apiKey: '', enabled: true });
|
||||
|
||||
// The rebuild runs inside the server, so the panel reads its progress instead
|
||||
// of holding the work: closing the modal does not stop it, and reopening the
|
||||
// tab picks up a run that is already in flight.
|
||||
useEffect(() => {
|
||||
if (tab !== 'storage') return;
|
||||
let alive = true;
|
||||
adminPreviewRebuildStatus()
|
||||
.then((next) => {
|
||||
if (alive) setRebuild(next);
|
||||
})
|
||||
.catch(() => undefined);
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [tab]);
|
||||
|
||||
const rebuildRunning = rebuild.state === 'running';
|
||||
useEffect(() => {
|
||||
if (tab !== 'storage' || !rebuildRunning) return;
|
||||
const timer = setInterval(() => {
|
||||
adminPreviewRebuildStatus()
|
||||
.then(setRebuild)
|
||||
.catch(() => undefined);
|
||||
}, 2000);
|
||||
return () => clearInterval(timer);
|
||||
}, [tab, rebuildRunning]);
|
||||
|
||||
const rebuildPreviews = async () => {
|
||||
setRebuildBusy(true);
|
||||
setError(null);
|
||||
setNote(null);
|
||||
try {
|
||||
const started = await adminRebuildPreviews();
|
||||
setRebuild(started);
|
||||
setNote(
|
||||
started.state === 'done'
|
||||
? 'Nothing to rebuild: every camera raw is a JPEG-only import'
|
||||
: `Rebuilding ${started.total} preview proxies`,
|
||||
);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Could not rebuild the previews');
|
||||
} finally {
|
||||
setRebuildBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const restoreCatalog = async (file: File | undefined) => {
|
||||
if (!file || busy) return;
|
||||
@@ -1188,6 +1250,47 @@ export default function AdminPanel({ user, onClose, onChanged, onRestored }: Pro
|
||||
container first (for example <code>-v /photos:/photos</code>), then use that container path.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<h3>Preview proxies</h3>
|
||||
<p className="muted small">
|
||||
Re-decode every camera raw from its original and replace its JPEG proxy, grid thumbnail
|
||||
and 16-bit sidecar. Run this after a change to the raw pipeline: edits, ratings and
|
||||
events are kept, and the originals are never modified.
|
||||
</p>
|
||||
<div className="btn-row">
|
||||
<button
|
||||
className="btn primary"
|
||||
onClick={() => void rebuildPreviews()}
|
||||
disabled={busy || rebuildBusy || rebuildRunning || rebuild.total === 0}
|
||||
title={
|
||||
rebuild.total === 0 && rebuild.state === 'done'
|
||||
? 'The last rebuild found no camera raws to process'
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
{rebuildRunning
|
||||
? `Rebuilding ${rebuild.done} / ${rebuild.total}…`
|
||||
: rebuildBusy
|
||||
? 'Starting…'
|
||||
: 'Rebuild previews'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{rebuildRunning && (
|
||||
<p className="muted small">
|
||||
{rebuild.done} of {rebuild.total} raws rebuilt
|
||||
{rebuild.failed ? ` · ${rebuild.failed} failed` : ''} · the server keeps going when
|
||||
this panel closes.
|
||||
</p>
|
||||
)}
|
||||
{rebuild.state === 'done' && (
|
||||
<p className="muted small">
|
||||
Rebuilt {rebuild.done - rebuild.failed} of {rebuild.total} raws
|
||||
{rebuild.sidecars ? `, ${rebuild.sidecars} with a 16-bit sidecar` : ''}
|
||||
{rebuild.failed ? ` · ${rebuild.failed} failed` : ''}.
|
||||
{rebuild.errors.length > 0 ? ` First failure: ${rebuild.errors[0]}` : ''}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user