Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4055925
Merge origin/fix/immich-sync-data-loss into feat/sync-immich
emmertex Nov 15, 2026
f512d20
SYNC-IMMICH: Replica::rekey moves a photo's record and memberships to…
emmertex Nov 15, 2026
4fbbd4e
SYNC-IMMICH: one key rule for photos (sha1:<hex>), content-hash alias…
emmertex Nov 15, 2026
d29d5b9
SYNC-IMMICH: link-only/file identity tests, SHA-1 check of synced ori…
emmertex Nov 15, 2026
363298e
Merge remote-tracking branch 'origin/main' into feat/sync-immich
emmertex Nov 15, 2026
5527c19
SYNC-IMMICH: cargo fmt (including code merged from the Immich fixes)
emmertex Nov 15, 2026
7796fb8
SYNC-IMMICH: keep the Immich checksum queue off wasm builds
emmertex Nov 15, 2026
4463c80
Merge remote-tracking branch 'origin/fix/immich-sync-data-loss' into …
emmertex Nov 15, 2026
a98c0e8
Merge remote-tracking branch 'origin/feat/sync2' into feat/sync-immich
emmertex Nov 15, 2026
3a30c2d
SYNC-IMMICH: a peer's SHA-1 is only a hint; the photo is hashed here …
emmertex Nov 15, 2026
e444708
IMM-IMPORT: importing a link-only photo's original keeps one photo
emmertex Nov 15, 2026
64ea22f
SYNC-IMMICH: Immich albums as replica collections (fixed Sync grant, …
emmertex Nov 15, 2026
5f67677
SYNC-IMMICH: Immich albums as collections under an Immich set, per-de…
emmertex Nov 15, 2026
8934741
SYNC-IMMICH: Settings UI, docs, manual and notes for Immich collections
emmertex Nov 15, 2026
313c192
SYNC-IMMICH: shared vs private Immich connections; the key travels ov…
emmertex Nov 15, 2026
f21dfeb
SYNC-IMMICH: the two-device Immich test shares its connections
emmertex Nov 15, 2026
dee5051
SYNC-ROLL: Camera Roll - {Device Name} collection watching the camera…
emmertex Nov 15, 2026
e75f2b5
SYNC-IMMICH: remove the name-matching Immich album rule (linkAlbum, s…
emmertex Nov 15, 2026
e7cf4a7
Merge remote-tracking branch 'origin/main' into feat/sync-immich
emmertex Nov 15, 2026
b181c59
SYNC-IMMICH: parity row cites the collections module instead of the r…
emmertex Nov 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions crates/engine/src/cmd/device_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,50 @@ pub fn specs() -> Vec<CommandSpec> {
let album = p.get("album").and_then(Value::as_u64).ok_or_else(|| bad("sync.skip", "missing `album`"))?;
sync::skip(s, album)
}),
cmd!(query "sync.immichRefresh", "List Immich Albums Now", [], None, "{}: list the albums of the Immich accounts shown as collections now (also done about once a minute) → {listing, errors}", always, |s, _p| {
#[cfg(not(target_arch = "wasm32"))]
return Ok(crate::cmd::immich::collections::refresh(s));
#[cfg(target_arch = "wasm32")]
{
let _ = s;
Ok(json!({"listing": 0, "errors": {}}))
}
}),
cmd!(
"sync.cameraRoll",
"Sync the Camera Roll",
[],
None,
"{on: bool, folder?}: this device's camera roll becomes the collection `Camera Roll - {device name}`, owned by this device and shared like any other: `folder` is watched and imported in place, and the collection holds every photo whose file is in it (on Android the folder is the platform's camera roll, learned from its listing) → {on, folder, collection}",
always,
|s, p| {
#[cfg(not(target_arch = "wasm32"))]
return sync::roll::set(s, p);
#[cfg(target_arch = "wasm32")]
{
let _ = (s, p);
Err(bad("sync.cameraRoll", "there is no camera roll here"))
}
}
),
cmd!(query "sync.cameraRollScan", "Look in the Camera Roll Now", [], None, "{}: import what is new in the camera-roll folder and file the collection now (also done when the folder changes) → {folder, photos}", always, |s, _p| {
#[cfg(not(target_arch = "wasm32"))]
return Ok(sync::roll::scan_now(s));
#[cfg(target_arch = "wasm32")]
{
let _ = s;
Ok(json!({"folder": null, "photos": 0}))
}
}),
cmd!(query "sync.cameraRollSeen", "Camera Roll Listed", [], None, "{paths}: the platform listed its camera roll (Android): on a device whose camera roll syncs without a folder of its own, their folder is the roll → {folder}", always, |s, p| {
#[cfg(not(target_arch = "wasm32"))]
return sync::roll::seen(s, p);
#[cfg(target_arch = "wasm32")]
{
let _ = (s, p);
Ok(json!({"folder": null}))
}
}),
cmd!(query "sync.now", "Sync Now", [], None, "{}: exchange with every device now → sync.status", always, |s, _p| {
sync::sync_now(s);
sync::status(s)
Expand Down
75 changes: 72 additions & 3 deletions crates/engine/src/cmd/immich.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ use crate::{Result, Session};
const LINK_PAGES: u32 = 10_000;
const PAGE_SIZE: u32 = 1000;

#[path = "immich_collections.rs"]
pub(crate) mod collections;
#[path = "immich_publish.rs"]
pub mod publish;
#[path = "immich_sidecars.rs"]
Expand Down Expand Up @@ -108,6 +110,8 @@ fn account_json(s: &Session, a: &Account) -> Value {
"permissions": a.permissions,
"missingPermissions": missing.iter().map(|(f, p)| json!({"feature": f, "permissions": p})).collect::<Vec<_>>(),
"pinned": a.pinned,
"collections": a.collections,
"shared": a.shared,
"pathMaps": a.path_maps,
"linked": linked,
"probable": probable,
Expand Down Expand Up @@ -840,6 +844,7 @@ pub fn pump(s: &mut Session, p: &Value) -> Result<Value> {
Msg::Sha1(done) => {
s.remote.sha1_busy = false;
for (id, path, h) in done {
s.remote.sha1_first.remove(&id);
// the photo may have moved or been relinked meanwhile
let same =
s.catalog.photo(id).is_some_and(|ph| matches!(&ph.source, Source::File { path: x } if *x == path) && ph.sha1.is_none());
Expand Down Expand Up @@ -909,12 +914,12 @@ pub fn pump(s: &mut Session, p: &Value) -> Result<Value> {
}
}
Msg::Downloaded(d) => finish_import(s, *d, &now),
Msg::ImmichAlbums(l) => collections::finish_listing(s, *l),
Msg::ImmichPushed(p) => collections::finish_push(s, *p),
Msg::ImmichPushDone => s.remote.coll.pushing = false,
Msg::Synced(d) => {
sync::finish(s, *d);
}
Msg::AlbumsSynced(d) => {
publish::finish_albums(s, *d);
}
Msg::Sidecars(d) => {
sidecars::finish(s, *d);
}
Expand All @@ -940,6 +945,7 @@ pub fn pump(s: &mut Session, p: &Value) -> Result<Value> {
sync::tick(s);
}
start_link_check(s);
collections::tick(s);
// the next SHA-1 batch
if bool_or(p, "sha1", true) && !s.remote.sha1_busy && s.remote.sha1_idle_at != Some(s.catalog.revision) {
let todo = remote::sha1_pending(s, remote::SHA1_BATCH);
Expand Down Expand Up @@ -1069,6 +1075,51 @@ fn finish_import(s: &mut Session, d: Downloaded, now: &str) {
remote::ImportProgress { active: false, requested: s.remote.import.requested, imported, skipped: d.skipped, present: have.len(), failed };
}

/// Newly imported photos whose original an Immich link-only photo already stands for: the
/// link-only photo takes the file (as when its original is downloaded) and the new entry goes,
/// so the catalog holds the photo once. → `(new id, the link-only photo that took its file)`.
pub(crate) fn merge_into_link_only(s: &mut Session, ids: &[PhotoId]) -> Vec<(PhotoId, PhotoId)> {
let mut by_sha1: std::collections::HashMap<String, (PhotoId, String)> = std::collections::HashMap::new();
for p in s.catalog.photos().filter(|p| p.preview_only.as_deref() == Some(LINK_ONLY) && !p.deleted) {
for r in s.catalog.remote_of(p.id).filter(|r| r.service == SERVICE) {
if let Some(d) = r.remote_checksum.as_deref().and_then(lcc_hash::Sha1Digest::parse) {
by_sha1.entry(d.to_hex()).or_insert((p.id, r.account_id.clone()));
}
}
}
if by_sha1.is_empty() {
return Vec::new();
}
let mut out = Vec::new();
for id in ids {
let Some(ph) = s.catalog.photo(*id) else { continue };
if ph.preview_only.is_some() || ph.copy_of.is_some() {
continue;
}
let (Some(sha1), Source::File { path }) = (ph.sha1.clone(), ph.source.clone()) else { continue };
let Some((keep, account)) = by_sha1.remove(&sha1) else { continue };
let albums = s.catalog.albums_of(*id);
if let Err(e) = adopt_original(s, keep, &account, Path::new(&path)) {
log::warn!("import: the Immich photo couldn't take `{path}`: {e}");
continue;
}
for a in albums {
if let Some(al) = s.catalog.album(a) {
let mut photos: Vec<PhotoId> = al.photos.iter().copied().filter(|p| p != id).collect();
if !photos.contains(&keep) {
photos.push(keep);
}
let _ = s.apply_system(Op::SetAlbumPhotos { id: a, photos });
}
}
if let Err(e) = s.apply_system(Op::RemovePhoto { id: *id }) {
log::warn!("import: {e}");
}
out.push((*id, keep));
}
out
}

/// A link-only photo's original arrived: point the photo at it.
fn adopt_original(s: &mut Session, id: PhotoId, account: &str, path: &Path) -> Result<()> {
let abs = path.to_string_lossy().to_string();
Expand Down Expand Up @@ -1280,6 +1331,24 @@ fn base_specs() -> Vec<CommandSpec> {
always,
disconnect
),
cmd!(
"immich.collections",
"Show Immich Albums as Collections",
[],
None,
"{account?, on: bool}: the account's albums show as collections in device sync (Settings ▸ Sync, under \"Immich\"); each device then picks per album none, previews or fullQuality → {account, collections}",
always,
collections::set_shown
),
cmd!(
"immich.share",
"Share Immich Connection with Synced Devices",
[],
None,
"{account?, on: bool}: share the connection with the devices this catalog syncs with: its API key goes to them over the encrypted device-sync channel into their key storage (never the catalog, replica, logs or results), and its albums' collections are told to them. off: the connection stays on this device and its collections are not told (devices that already got the key keep it: revoke the key in Immich to stop them) → {account, shared}",
always,
collections::set_shared
),
cmd!(query "immich.status", "Immich Status", [], None, "{check?: bool (also contact each server), background?: bool (do that on workers; results in later calls' `server`)} → {accounts: [{id, url, userName, version, permissions, linked, probable, link, server?, checking}], secretStore, connecting, connected?}", always, status),
cmd!(query "immich.answer", "Immich Background Result", [], None, "{key, keep?: bool}: the result of a call made with background: true (immich.libraries, immich.authStatus, immich.unlockSession, immich.scanLibraries, immich.importPeople, immich.pushPeople; they return {started, key}); taken once unless keep → {done: true, result} or {done: false, running}; remote.pump lists the waiting keys in `answers`", always, answer),
cmd!(query "immich.authStatus", "Immich Auth Status", [], None, "{account?, background?: bool (on a worker: {started, key}, the result through immich.answer)}: whether this app's server session is elevated (locked folders visible to its listings), and the unlock secrets the account has → {ok, account, isElevated, password, pinCode, expiresAt?, pinExpiresAt?} or {ok: false, error}", always, auth_status),
Expand Down
Loading
Loading