Add the optional Immich integration and manual gallery push

Immich connections stay server-side with an encrypted API key, albums can be
imported, and photos are only sent back when an event's push button is pressed:
originals upload once, edited photos re-render, and edits hashes plus checksums
skip anything already in Immich. This also lands the accompanying editor, cloud
and administration work that was still uncommitted.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
2026-11-25 17:43:05 +00:00
parent e0c76ba965
commit 0b3ab76405
26 changed files with 4323 additions and 144 deletions
+159 -1
View File
@@ -15,14 +15,17 @@ import {
adminCreateUser,
adminDeleteEvent,
adminDeleteUser,
adminDisconnectImmich,
adminRestoreCatalog,
adminRevokeInvite,
adminOverview,
adminRenameEvent,
adminSaveImmich,
adminSaveMail,
adminSchedulePrune,
adminSetQuota,
adminSetStorage,
adminTestImmich,
adminTestMail,
adminUpdateUser,
adminWarnUser,
@@ -68,7 +71,7 @@ const planSummary = (quota: AdminQuota) => {
return parts.length ? parts.join(', ') : 'nothing';
};
type Tab = 'users' | 'invites' | 'content' | 'storage' | 'quotas' | 'backup';
type Tab = 'users' | 'invites' | 'content' | 'storage' | 'quotas' | 'immich' | 'backup';
const inviteUrl = (token: string) => `${window.location.origin}/join/${token}`;
@@ -112,6 +115,8 @@ export default function AdminPanel({ user, onClose, onChanged, onRestored }: Pro
const [quotaDrafts, setQuotaDrafts] = useState<Record<string, string>>({});
const [mailDraft, setMailDraft] = useState({ user: '', appPassword: '', from: '' });
const [mail, setMail] = useState<MailStatus | null>(null);
const [immichDraft, setImmichDraft] = useState({ url: '', apiKey: '', enabled: true });
const restoreCatalog = async (file: File | undefined) => {
if (!file || busy) return;
@@ -161,6 +166,11 @@ export default function AdminPanel({ user, onClose, onChanged, onRestored }: Pro
user: current.user || next.mail.user,
from: current.from || next.mail.from,
}));
setImmichDraft((current) => ({
url: next.immich.hasKey ? current.url || next.immich.url : next.immich.url,
apiKey: '',
enabled: next.immich.hasKey ? (current.url ? current.enabled : next.immich.enabled) : true,
}));
setRootInput((current) => (current ? current : next.storage.root));
onChanged();
}, [onChanged]);
@@ -174,6 +184,13 @@ export default function AdminPanel({ user, onClose, onChanged, onRestored }: Pro
setOverview(next);
setMail(next.mail);
setMailDraft({ user: next.mail.user, appPassword: '', from: next.mail.from });
// A connection being set up for the first time defaults to on; the box
// would otherwise be unchecked and silently save publishing as off.
setImmichDraft({
url: next.immich.url,
apiKey: '',
enabled: next.immich.hasKey ? next.immich.enabled : true,
});
setRootInput(next.storage.root);
setQuotaDrafts(
Object.fromEntries(
@@ -345,6 +362,42 @@ export default function AdminPanel({ user, onClose, onChanged, onRestored }: Pro
setNote(`Test email sent to ${user.email}`);
});
const saveImmich = () =>
run(async () => {
const next = await adminSaveImmich({
url: immichDraft.url.trim(),
apiKey: immichDraft.apiKey,
enabled: immichDraft.enabled,
});
setImmichDraft({ url: next.url, apiKey: '', enabled: next.enabled });
setNote(
next.enabled
? 'Immich connection saved for every account'
: 'Immich connection saved; automatic publishing is off',
);
});
const testImmich = () =>
run(async () => {
const result = await adminTestImmich();
setNote(
`Connected to Immich ${result.version} · ${result.albumCount} album${
result.albumCount === 1 ? '' : 's'
}`,
);
});
const disconnectImmichConnection = () => {
if (!window.confirm('Remove the server-wide Immich connection? Existing albums and photos stay in Immich.')) {
return;
}
void run(async () => {
const next = await adminDisconnectImmich();
setImmichDraft({ url: next.url, apiKey: '', enabled: next.enabled });
setNote('Immich connection removed');
});
};
const renameEvent = () => {
if (!editEvent) return;
const name = editEvent.name.trim();
@@ -404,6 +457,9 @@ export default function AdminPanel({ user, onClose, onChanged, onRestored }: Pro
<button className={`tab ${tab === 'quotas' ? 'on' : ''}`} onClick={() => setTab('quotas')}>
Quotas
</button>
<button className={`tab ${tab === 'immich' ? 'on' : ''}`} onClick={() => setTab('immich')}>
Immich
</button>
<button className={`tab ${tab === 'backup' ? 'on' : ''}`} onClick={() => setTab('backup')}>
Backup
</button>
@@ -926,6 +982,108 @@ export default function AdminPanel({ user, onClose, onChanged, onRestored }: Pro
</p>
</div>
</section>
) : tab === 'immich' ? (
<section className="admin-section">
<h3>Immich connection</h3>
<p className="muted small">
One connection is shared by every account. When it is enabled, importing into a
Luminary event creates a matching Immich album, publishes the originals there, and
saves edited versions to the same album.
</p>
<label className="field">
<span>Immich server address</span>
<input
value={immichDraft.url}
spellCheck={false}
placeholder="http://192.168.1.10:2283"
onChange={(e) =>
setImmichDraft((current) => ({ ...current, url: e.target.value }))
}
onKeyDown={(e) => e.key === 'Enter' && saveImmich()}
/>
</label>
<label className="field">
<span>API key</span>
<input
type="password"
autoComplete="off"
value={immichDraft.apiKey}
placeholder={overview.immich.hasKey ? 'Saved — type to replace' : 'Immich API key'}
onChange={(e) =>
setImmichDraft((current) => ({ ...current, apiKey: e.target.value }))
}
onKeyDown={(e) => e.key === 'Enter' && saveImmich()}
/>
</label>
<label className="check-row">
<input
type="checkbox"
checked={immichDraft.enabled}
disabled={busy}
onChange={(e) =>
setImmichDraft((current) => ({ ...current, enabled: e.target.checked }))
}
/>
Automatically publish event photos and edits
</label>
<div className="btn-row">
<button
className="btn primary"
onClick={saveImmich}
disabled={
busy ||
!immichDraft.url.trim() ||
(!immichDraft.apiKey && !overview.immich.hasKey)
}
>
Save connection
</button>
<button
className="btn ghost"
onClick={testImmich}
disabled={busy || !overview.immich.hasKey}
>
Test connection
</button>
{overview.immich.hasKey && (
<button
className="btn ghost"
onClick={disconnectImmichConnection}
disabled={busy}
>
Disconnect
</button>
)}
</div>
{overview.immich.configured ? (
<div className={`banner ${overview.immich.enabled ? 'ok' : 'info'}`}>
{overview.immich.enabled
? 'Connected and automatic publishing is on.'
: 'Connection saved; automatic publishing is off.'}{' '}
{overview.immich.version ? `Immich ${overview.immich.version}.` : 'Test it to verify access.'}
</div>
) : (
<div className="banner info">
Add the server address and API key to enable Immich publishing.
</div>
)}
<div className="admin-note">
<p>
The key needs <code>album.read</code>, <code>album.create</code>,{' '}
<code>albumAsset.create</code>, <code>asset.read</code>,{' '}
<code>asset.download</code>, <code>asset.upload</code> and{' '}
<code>asset.update</code>. Add <code>asset.delete</code> only if originals should
move to the Immich trash after an edited version is uploaded.
</p>
<p className="muted small">
The key is encrypted on the server and never sent back to a browser. Existing
albums already in Immich stay untouched if the connection is removed.
</p>
</div>
</section>
) : tab === 'backup' ? (
<section className="admin-section">
<h3>Catalog backup</h3>
+10
View File
@@ -12,6 +12,7 @@ interface Props {
onLogout: () => void;
onSync: () => void;
onAdmin: () => void;
onImmich: () => void;
onClose: () => void;
}
@@ -32,6 +33,7 @@ export default function CloudPanel({
onLogout,
onSync,
onAdmin,
onImmich,
onClose,
}: Props) {
const [mode, setMode] = useState<'signin' | 'signup'>('signin');
@@ -121,6 +123,14 @@ export default function CloudPanel({
Administration
</button>
)}
<button
className="btn ghost"
onClick={onImmich}
disabled={busy}
title="Optional: sync albums with your own Immich server"
>
Immich sync
</button>
</div>
{note && <div className="banner ok">{note}</div>}
</div>
+18
View File
@@ -128,6 +128,9 @@ interface Props {
onLocalClipboard: (layer: LocalLayer | null) => void;
onExport: () => void;
onPrint: () => void;
canPushImmich?: boolean;
onPushImmich?: () => void;
onOpenImmich?: () => void;
presets: Preset[];
onSavePreset: (name: string, edits: Edits) => void;
onDelete: () => void;
@@ -155,6 +158,9 @@ export default function Develop({
onLocalClipboard,
onExport,
onPrint,
canPushImmich = false,
onPushImmich,
onOpenImmich,
presets,
onSavePreset,
onDelete,
@@ -1453,6 +1459,12 @@ export default function Develop({
{ label: 'Paste settings', shortcut: '⌘V', onSelect: onPaste, disabled: !clipboard },
{ label: 'Reset settings', onSelect: resetAll },
'separator',
...(canPushImmich && onPushImmich
? ([{ label: 'Send edit to Immich', onSelect: onPushImmich }] as MenuEntry[])
: []),
...(onOpenImmich
? ([{ label: 'Open in Immich', onSelect: onOpenImmich }] as MenuEntry[])
: []),
{ label: 'Export…', onSelect: onExport },
{ label: 'Delete photo…', danger: true, onSelect: onDelete },
];
@@ -1462,6 +1474,12 @@ export default function Develop({
{ label: 'Paste settings', onSelect: onPaste, disabled: !clipboard },
{ label: 'Reset settings', onSelect: resetAll },
'separator',
...(canPushImmich && onPushImmich
? ([{ label: 'Send edit to Immich', onSelect: onPushImmich }] as MenuEntry[])
: []),
...(onOpenImmich
? ([{ label: 'Open in Immich', onSelect: onOpenImmich }] as MenuEntry[])
: []),
{ label: 'Export…', onSelect: onExport },
{ label: 'Delete photo…', danger: true, onSelect: onDelete },
];
+27 -2
View File
@@ -17,9 +17,11 @@ interface Props {
photos: PhotoRecord[];
eventId: string;
onSelectEvent: (id: string) => void;
onCreate: (name: string) => Promise<void> | void;
immichEnabled?: boolean;
onCreate: (name: string, immichGallery?: boolean) => Promise<void> | void;
onRename: (id: string, name: string) => void;
onDelete: (id: string) => void;
onSyncGallery?: (id: string) => void;
onReorderEvents: (dragId: string, targetId: string) => void;
onDropPhotos: (ids: string[], eventId: string) => void;
trashOpen: boolean;
@@ -39,9 +41,11 @@ export default function EventSidebar({
photos,
eventId,
onSelectEvent,
immichEnabled = false,
onCreate,
onRename,
onDelete,
onSyncGallery,
onReorderEvents,
onDropPhotos,
trashOpen,
@@ -55,6 +59,7 @@ export default function EventSidebar({
}: Props) {
const [adding, setAdding] = useState(false);
const [name, setName] = useState('');
const [createGallery, setCreateGallery] = useState(false);
const [dropTarget, setDropTarget] = useState<string | null>(null);
const counts = new Map<string, number>();
@@ -72,8 +77,9 @@ export default function EventSidebar({
setAdding(false);
return;
}
await onCreate(name);
await onCreate(name, createGallery);
setName('');
setCreateGallery(false);
setAdding(false);
};
@@ -189,6 +195,16 @@ export default function EventSidebar({
<button className="btn primary small" onClick={() => void submit()}>
Add
</button>
{immichEnabled && (
<label className="check-row small new-event-gallery">
<input
type="checkbox"
checked={createGallery}
onChange={(e) => setCreateGallery(e.target.checked)}
/>
Create Immich gallery
</label>
)}
</div>
)}
@@ -234,6 +250,15 @@ export default function EventSidebar({
<span className="event-count">{counts.get(event.id) ?? 0}</span>
</button>
<div className="event-tools">
{immichEnabled && event.immich && onSyncGallery && (
<button
className="icon-btn"
title="Push edits and originals to this event's Immich gallery"
onClick={() => onSyncGallery(event.id)}
>
☁
</button>
)}
<button
className="icon-btn"
title="Rename event"
+431
View File
@@ -0,0 +1,431 @@
import { useCallback, useEffect, useState } from 'react';
import type { ImmichAlbum, ImmichImportJob, ImmichStatus } from '../lib/api';
import {
disconnectImmich,
getImmichJob,
getImmichStatus,
immichAlbums,
immichImportAlbum,
saveImmichSettings,
testImmich,
} from '../lib/api';
interface Props {
onClose: () => void;
onChanged: () => void;
onToast: (message: string) => void;
}
const fmtDate = (ms: number | null) =>
ms
? new Date(ms).toLocaleString(undefined, {
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: '2-digit',
})
: 'never';
/**
* Optional, per-account Immich setup. Nothing here is shown anywhere else in
* the app until the user saves a connection and turns the integration on.
*/
export default function ImmichPanel({ onClose, onChanged, onToast }: Props) {
const [status, setStatus] = useState<ImmichStatus | null>(null);
const [loading, setLoading] = useState(true);
const [saving, setSaving] = useState(false);
const [error, setError] = useState<string | null>(null);
const [draft, setDraft] = useState({ url: '', apiKey: '' });
const [albums, setAlbums] = useState<ImmichAlbum[] | null>(null);
const [albumsLoading, setAlbumsLoading] = useState(false);
const [job, setJob] = useState<ImmichImportJob | null>(null);
const load = useCallback(async () => {
try {
const next = await getImmichStatus();
setStatus(next);
setDraft((current) => ({ url: current.url || next.url, apiKey: '' }));
} catch (err) {
setError(err instanceof Error ? err.message : 'Could not read the Immich settings');
} finally {
setLoading(false);
}
}, []);
useEffect(() => {
void load();
}, [load]);
useEffect(() => {
const onKey = (event: KeyboardEvent) => {
if (event.key !== 'Escape') return;
event.preventDefault();
event.stopImmediatePropagation();
if (!saving) onClose();
};
window.addEventListener('keydown', onKey, true);
return () => window.removeEventListener('keydown', onKey, true);
}, [saving, onClose]);
useEffect(() => {
if (!job || job.state !== 'running') return;
let alive = true;
const timer = setInterval(() => {
void getImmichJob(job.id)
.then((next) => {
if (!alive) return;
setJob(next);
if (next.state === 'running') return;
onToast(next.message || 'Immich import finished');
setAlbums(null);
void load();
onChanged();
})
.catch((err) => {
if (!alive) return;
setError(err instanceof Error ? err.message : 'Could not check the import');
setJob({ ...job, state: 'error' });
});
}, 1500);
return () => {
alive = false;
clearInterval(timer);
};
}, [job, load, onChanged, onToast]);
const save = async (patch: Record<string, unknown> = {}) => {
if (saving) return null;
setSaving(true);
setError(null);
try {
const next = await saveImmichSettings({
url: draft.url.trim(),
apiKey: draft.apiKey,
...patch,
});
setStatus(next);
setDraft({ url: next.url, apiKey: '' });
onChanged();
return next;
} catch (err) {
setError(err instanceof Error ? err.message : 'Could not save the Immich connection');
return null;
} finally {
setSaving(false);
}
};
const test = async () => {
if (saving) return;
setSaving(true);
setError(null);
try {
const result = await testImmich();
onToast(
`Connected to Immich ${result.version} · ${result.albumCount} album${result.albumCount === 1 ? '' : 's'}`,
);
await load();
} catch (err) {
setError(err instanceof Error ? err.message : 'Could not reach Immich');
} finally {
setSaving(false);
}
};
const loadAlbums = async () => {
if (albumsLoading) return;
setAlbumsLoading(true);
setError(null);
try {
setAlbums(await immichAlbums());
} catch (err) {
setError(err instanceof Error ? err.message : 'Could not load Immich albums');
} finally {
setAlbumsLoading(false);
}
};
const startImport = async (album: ImmichAlbum) => {
if (job?.state === 'running') return;
if (
album.eventId &&
!window.confirm(
`“${album.name}” is already linked to a Luminary event. Importing again adds new photos and skips ones already here.`,
)
) {
return;
}
setError(null);
try {
setJob(await immichImportAlbum(album.id));
} catch (err) {
setError(err instanceof Error ? err.message : 'Could not start the import');
}
};
const disconnect = async () => {
if (!window.confirm('Disconnect Immich? Imported events and photos stay in the library.')) return;
setSaving(true);
setError(null);
try {
const next = await disconnectImmich();
setStatus(next);
setDraft({ url: next.url, apiKey: '' });
setAlbums(null);
setJob(null);
onChanged();
onToast('Immich disconnected');
} catch (err) {
setError(err instanceof Error ? err.message : 'Could not disconnect');
} finally {
setSaving(false);
}
};
const configured = Boolean(status?.configured);
const enabled = Boolean(status?.enabled);
const managed = Boolean(status?.managed);
const running = job?.state === 'running';
return (
<div className="modal-backdrop" onPointerDown={(e) => e.target === e.currentTarget && onClose()}>
<div className="modal immich-modal">
<header className="modal-head">
<h2>Immich sync</h2>
<button className="icon-btn" onClick={onClose} title="Close (Esc)">
✕
</button>
</header>
<div className="modal-body">
<p className="muted small immich-intro">
{managed
? 'This server uses an Immich connection managed by an administrator. You can import albums, but the server address and API key are managed centrally.'
: 'Optional and private to your account. Your API key is stored encrypted on the server and is never sent to the browser. Nothing changes in the library until you turn this on.'}
</p>
{managed && status?.url && (
<div className="banner info">
Shared Immich server: <code>{status.url}</code>
</div>
)}
{loading && !status ? (
<p className="muted small">Checking…</p>
) : (
<>
<label className="field">
<span>Immich server</span>
<input
value={draft.url}
spellCheck={false}
placeholder="http://192.168.1.10:2283"
disabled={saving || managed}
onChange={(e) => setDraft((current) => ({ ...current, url: e.target.value }))}
onKeyDown={(e) => e.key === 'Enter' && void save()}
/>
</label>
<label className="field">
<span>API key</span>
<input
type="password"
value={draft.apiKey}
disabled={saving || managed}
placeholder={
managed
? 'Managed by an administrator'
: status?.hasKey
? 'Saved — type to replace'
: 'Immich API key'
}
onChange={(e) => setDraft((current) => ({ ...current, apiKey: e.target.value }))}
onKeyDown={(e) => e.key === 'Enter' && void save()}
/>
</label>
<div className="btn-row">
<button
className="btn primary"
onClick={() => void save()}
disabled={
saving || managed || !draft.url.trim() || (!draft.apiKey && !status?.hasKey)
}
>
{saving ? 'Saving…' : configured ? 'Save connection' : 'Connect'}
</button>
<button className="btn ghost" onClick={() => void test()} disabled={saving || !status?.hasKey}>
Test connection
</button>
{configured && !managed && (
<button className="btn ghost" onClick={() => void disconnect()} disabled={saving}>
Disconnect
</button>
)}
</div>
<p className="muted small">
Create a key in Immich under Account Settings → API Keys. It needs{' '}
<code>album.read</code>, <code>album.create</code>, <code>albumAsset.create</code>,{' '}
<code>asset.read</code>,
<code>asset.download</code>, <code>asset.upload</code> and <code>asset.update</code>;
add <code>tag.read</code>, <code>tag.create</code> and <code>tag.asset</code> for
keyword sync, and <code>asset.delete</code> only if you want originals moved to the
Immich trash after an upload.
</p>
{configured && (
<>
<div className="subhead">
<span>Integration</span>
<span className="muted small">
{status?.version ? `Immich ${status.version}` : 'Not tested yet'}
</span>
</div>
<label className="check-row">
<input
type="checkbox"
checked={enabled}
disabled={saving || managed}
onChange={(e) => void save({ enabled: e.target.checked })}
/>
Show Immich tools in my account (import albums, send edits back)
</label>
<p className="muted small">
Nothing is uploaded while you edit. Press the ☁ button on an event to push
its edited photos and any originals Immich has not seen yet.
</p>
<label className="check-row">
<input
type="checkbox"
checked={Boolean(status?.trashOriginal)}
disabled={saving || !enabled || managed}
onChange={(e) => void save({ trashOriginal: e.target.checked })}
/>
After uploading an edit, move the original to the Immich trash
</label>
<p className="muted small">
Recoverable in Immich. Luminary never permanently deletes the Immich original.
</p>
{enabled && (
<>
<div className="subhead">
<span>Albums</span>
<span className="muted small">Only linked albums sync automatically</span>
</div>
<div className="admin-table">
<div className="admin-row admin-row-head content-row">
<span>Album</span>
<span>Photos</span>
<span>Last sync</span>
<span>Actions</span>
</div>
{albums === null ? (
<p className="muted small">
{albumsLoading
? 'Loading albums…'
: 'Choose Refresh to list albums from this Immich account.'}
</p>
) : albums.length === 0 ? (
<p className="muted small">This Immich account has no albums.</p>
) : (
albums.map((album) => (
<div className="admin-row content-row" key={album.id}>
<div className="admin-event-name">
<strong>{album.name}</strong>
<div className="muted small">
{album.updatedAt
? `Updated ${fmtDate(album.updatedAt)}`
: 'Immich album'}
</div>
</div>
<span className="admin-num">{album.assetCount}</span>
<span className="admin-num">
{album.lastSyncAt ? fmtDate(album.lastSyncAt) : '—'}
</span>
<div className="admin-actions">
{album.kind === 'gallery' ? (
<span className="muted small">Gallery</span>
) : (
<button
className="btn small"
disabled={running}
onClick={() => void startImport(album)}
>
{album.eventId ? 'Sync again' : 'Import'}
</button>
)}
</div>
</div>
))
)}
</div>
<div className="btn-row">
<button
className="btn ghost"
onClick={() => void loadAlbums()}
disabled={albumsLoading}
>
{albumsLoading ? 'Loading…' : 'Refresh albums'}
</button>
</div>
</>
)}
{job && (
<div className="admin-note">
<p>
<strong>{job.albumName || 'Album'}</strong> ·{' '}
{job.state === 'running'
? job.scheduled
? 'Syncing in the background…'
: 'Importing…'
: job.state === 'done'
? 'Complete'
: 'Stopped'}
</p>
<div className="quota-meter" aria-label="Import progress">
<span
className={job.state === 'error' ? 'warn' : ''}
style={{
width: `${job.total ? Math.round(((job.done + job.skipped + job.failed) / job.total) * 100) : 0}%`,
}}
/>
</div>
<p className="muted small">
{job.done} imported · {job.skipped} already present
{job.failed ? ` · ${job.failed} failed` : ''}
</p>
{job.message && <p className="muted small">{job.message}</p>}
{job.errors.length > 0 && (
<ul className="muted small">
{job.errors.map((message) => (
<li key={message}>{message}</li>
))}
</ul>
)}
</div>
)}
</>
)}
</>
)}
{error && <div className="banner error">{error}</div>}
</div>
<footer className="modal-foot">
<span className="muted small">
Nothing uploads automatically. Use ☁ on an event to push its edits and originals.
</span>
<button className="btn" onClick={onClose}>
Done
</button>
</footer>
</div>
</div>
);
}
+116 -2
View File
@@ -1,4 +1,5 @@
import { useEffect, useMemo, useRef, useState } from 'react';
import { publishImmichOriginal } from '../lib/api';
import type { CloudImport, ImportProgress } from '../lib/import';
import { importFiles, isSupportedFile } from '../lib/import';
import { isRawFile, RAW_ACCEPT } from '../lib/raw';
@@ -13,6 +14,9 @@ interface Props {
onClose: () => void;
onImported: (photos: PhotoRecord[], eventId: string) => void;
onCreateEvent: (name: string) => Promise<EventRecord>;
/** Turns on the optional Immich gallery for the created/target event. */
immichEnabled?: boolean;
onCreateImmichGallery?: (eventId: string) => Promise<EventRecord>;
cloud?: CloudImport | null;
onNeedServer: () => void;
}
@@ -25,6 +29,8 @@ export default function ImportModal({
onClose,
onImported,
onCreateEvent,
immichEnabled = false,
onCreateImmichGallery,
cloud,
onNeedServer,
}: Props) {
@@ -37,11 +43,16 @@ export default function ImportModal({
const [progress, setProgress] = useState<ImportProgress | null>(null);
const [failures, setFailures] = useState<string[]>([]);
const [allowDuplicates, setAllowDuplicates] = useState(false);
const [createGallery, setCreateGallery] = useState(immichEnabled);
const [galleryCreated, setGalleryCreated] = useState(false);
const [galleryError, setGalleryError] = useState<string | null>(null);
const [summary, setSummary] = useState<{
imported: number;
failed: number;
skipped: number;
cancelled: boolean;
published: number;
publishFailed: number;
} | null>(null);
const inputRef = useRef<HTMLInputElement>(null);
const abortRef = useRef<AbortController | null>(null);
@@ -56,6 +67,12 @@ export default function ImportModal({
);
const readyFiles = allowDuplicates ? files : files.filter((file) => !duplicateFiles.includes(file));
useEffect(() => {
setGalleryCreated(false);
setGalleryError(null);
setCreateGallery(immichEnabled);
}, [eventId, immichEnabled]);
useEffect(() => {
// Capture phase: Escape closes this dialog even while a photo is open behind it.
const onKey = (e: KeyboardEvent) => {
@@ -91,16 +108,67 @@ export default function ImportModal({
const created = await onCreateEvent(newName || `Event ${new Date().toLocaleDateString()}`);
targetId = created.id;
}
let hasGallery = Boolean(events.find((event) => event.id === targetId)?.immich);
if (
createGallery &&
!galleryCreated &&
onCreateImmichGallery &&
!hasGallery
) {
try {
await onCreateImmichGallery(targetId);
hasGallery = true;
setGalleryCreated(true);
} catch (err) {
setGalleryError(
err instanceof Error ? err.message : 'The Immich gallery could not be created',
);
}
}
const result = await importFiles(readyFiles, targetId, [], setProgress, cloud ?? null, controller.signal);
if (result.photos.length) onImported(result.photos, targetId);
let published = 0;
let publishFailed = 0;
const publishFailures: string[] = [];
if (hasGallery && immichEnabled && cloud && result.photos.length) {
const total = result.photos.length;
for (let index = 0; index < total; index++) {
if (controller.signal.aborted) break;
const photo = result.photos[index];
setProgress({
done: index,
total,
current: `Adding ${photo.name} to the Immich gallery…`,
});
try {
const pushed = await publishImmichOriginal(photo.id);
if (!pushed.skipped) published += 1;
} catch (err) {
publishFailed += 1;
publishFailures.push(
`${photo.name} — Immich: ${err instanceof Error ? err.message : 'upload failed'}`,
);
}
}
setProgress({ done: total, total, current: '' });
}
const skipped = allowDuplicates ? 0 : duplicateFiles.length;
setSummary({
imported: result.photos.length,
failed: result.failed.length,
skipped,
cancelled: Boolean(result.cancelled),
published,
publishFailed,
});
if (result.failed.length) setFailures(result.failed.map((f) => `${f.name} — ${f.reason}`));
if (result.failed.length || publishFailures.length) {
setFailures([
...result.failed.map((f) => `${f.name} — ${f.reason}`),
...publishFailures,
]);
}
} catch (err) {
setFailures([err instanceof Error ? err.message : 'Import failed']);
} finally {
@@ -152,6 +220,45 @@ export default function ImportModal({
</label>
)}
{immichEnabled &&
!galleryCreated &&
!events.find((event) => event.id === eventId)?.immich && (
<>
<label className="check-row">
<input
type="checkbox"
checked={createGallery}
onChange={(e) => setCreateGallery(e.target.checked)}
disabled={busy}
/>
Create an Immich album and publish originals
</label>
<p className="muted small">
Luminary creates a matching album in Immich, uploads each original into it, and
saves edited versions to the same album as you work.
</p>
</>
)}
{galleryCreated && (
<p className="muted small">
Immich album linked. Imported originals will upload automatically, and edits will be
saved there as new versions.
</p>
)}
{!galleryCreated &&
immichEnabled &&
Boolean(events.find((event) => event.id === eventId)?.immich) && (
<p className="muted small">
Imported originals will be added to this event&apos;s Immich album automatically.
Edits will be saved there too.
</p>
)}
{galleryError && (
<div className="banner warn">
<strong>Immich gallery not created.</strong> {galleryError}
</div>
)}
<div
className={`dropzone ${dragOver ? 'over' : ''}`}
onDragOver={(e) => {
@@ -260,18 +367,25 @@ export default function ImportModal({
{summary.imported} imported
{summary.skipped ? ` · ${summary.skipped} duplicate${summary.skipped === 1 ? '' : 's'} skipped` : ''}
{summary.failed ? ` · ${summary.failed} failed` : ''}
{summary.published ? ` · ${summary.published} added to Immich` : ''}
{summary.publishFailed
? ` · ${summary.publishFailed} Immich upload${summary.publishFailed === 1 ? '' : 's'} failed`
: ''}
</span>
<p className="muted small">
{summary.cancelled
? 'Files already in progress were allowed to finish. The imported photos are in the catalog.'
: 'New photos are selected in the library and ready to review.'}
{summary.published
? ' The imported photos were added to the event\'s Immich gallery.'
: ''}
</p>
</div>
)}
{failures.length > 0 && (
<div className="failures">
<strong>Some files could not be imported</strong>
<strong>Some files had problems</strong>
<ul>
{failures.map((f) => (
<li key={f}>{f}</li>
+14
View File
@@ -15,6 +15,8 @@ interface Props {
onBulkRate: (rating: number) => void;
onBulkFlag: (flag: Flag) => void;
onBulkColor: (color: ColorLabel) => void;
onSendToImmich?: () => void;
immichBusy?: boolean;
onDelete: () => void;
onExport: () => void;
onCompare: () => void;
@@ -51,6 +53,8 @@ export default function LibraryGrid({
onBulkRate,
onBulkFlag,
onBulkColor,
onSendToImmich,
immichBusy = false,
onDelete,
onExport,
onCompare,
@@ -277,6 +281,16 @@ export default function LibraryGrid({
<button className="btn ghost small" onClick={onMerge} disabled={selected.length < 2}>
Merge
</button>
{onSendToImmich && (
<button
className="btn ghost small"
onClick={onSendToImmich}
disabled={immichBusy}
title="Send rendered edits for this selection to Immich"
>
Send to Immich
</button>
)}
<button className="btn ghost small" onClick={onExport}>
Export
</button>