Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

refactor([issue-912]): overlap regen route reads + dedupe lightbox button handlers

[._.]/ Adam Eivyfdc59f982003
diff --git a/client/src/components/media/MediaLightbox.jsx b/client/src/components/media/MediaLightbox.jsx
index 6cade48e9b..87848e75f1 100644
--- a/client/src/components/media/MediaLightbox.jsx
+++ b/client/src/components/media/MediaLightbox.jsx
@@ -371,6 +371,23 @@ function SettingsPane({
onClose?.();
handler?.(item);
};
+ // Shared handler for the in-place async actions (Clean / Regenerate): guard
+ // against double-fire, flip the busy flag, run the action (the caller toasts
+ // its own error so we just stay open on throw), and close on success.
+ const runBusyAction = (busy, setBusy, action) => async () => {
+ if (busy) return;
+ setBusy(true);
+ let ok = false;
+ try {
+ await action(item);
+ ok = true;
+ } catch {
+ // Caller toasts its own error; stay open so the user can retry.
+ } finally {
+ setBusy(false);
+ }
+ if (ok) onClose();
+ };
// Local draft state debounces saves so each keystroke doesn't PATCH.
// onSaveRef keeps the debounce effect off the parent's render churn —
// page components pass inline-arrow onAnnotationChange callbacks, which
@@ -591,20 +608,7 @@ function SettingsPane({
<button
type="button"
disabled={cleaning}
- onClick={async () => {
- if (cleaning) return;
- setCleaning(true);
- let ok = false;
- try {
- await onClean(item);
- ok = true;
- } catch {
- // Caller toasts its own error; stay open so the user can retry.
- } finally {
- setCleaning(false);
- }
- if (ok) onClose();
- }}
+ onClick={runBusyAction(cleaning, setCleaning, onClean)}
title={CLEAN_TOOLTIP}
aria-label="Clean image"
className="flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 text-xs bg-port-warning/80 text-white hover:opacity-90 rounded disabled:opacity-50 disabled:cursor-not-allowed"
@@ -616,20 +620,7 @@ function SettingsPane({
<button
type="button"
disabled={regenerating}
- onClick={async () => {
- if (regenerating) return;
- setRegenerating(true);
- let ok = false;
- try {
- await onRegenerate(item);
- ok = true;
- } catch {
- // Caller toasts its own error; stay open so the user can retry.
- } finally {
- setRegenerating(false);
- }
- if (ok) onClose();
- }}
+ onClick={runBusyAction(regenerating, setRegenerating, onRegenerate)}
title="Regenerate through a local FLUX model (img2img) to overwrite SynthID watermarking. Creates a new variant; the original is kept."
aria-label="Regenerate image to defeat SynthID watermark"
className="flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 text-xs bg-port-accent/80 text-white hover:opacity-90 rounded disabled:opacity-50 disabled:cursor-not-allowed"
diff --git a/server/routes/imageGen.js b/server/routes/imageGen.js
index bb55ce8fe9..f49f1ead40 100644
--- a/server/routes/imageGen.js
+++ b/server/routes/imageGen.js
@@ -638,14 +638,18 @@ router.post('/:filename/regenerate', asyncHandler(async (req, res) => {
if (!sourceAbsPath) {
throw new ServerError('Image not found', { status: 404, code: 'NOT_FOUND' });
}
- const { metadata: sourceMeta } = await local.readImageSidecar(filename);
+ // Sidecar (for prompt/model) and the on-disk dimension probe have no data
+ // dependency — overlap the two reads.
+ const [{ metadata: sourceMeta }, sourceDims] = await Promise.all([
+ local.readImageSidecar(filename),
+ readImageDimensions(sourceAbsPath),
+ ]);
const backend = await resolveRegenBackend({ sourceModelId: sourceMeta.modelId });
if (!backend.available) {
throw new ServerError(backend.reason, { status: 400, code: 'REGEN_BACKEND_UNAVAILABLE' });
}
- const sourceDims = await readImageDimensions(sourceAbsPath);
const strength = body.strength ?? DEFAULT_REGEN_STRENGTH;
const params = buildRegenParams({
filename,