Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

Merge PR #948

Claude5861591307b8
diff --cc crates/engine/src/cmd/geocode.rs
index 000000000,21b92c6e4..ddbe6b13a
mode 000000,100644..100644
--- a/crates/engine/src/cmd/geocode.rs
+++ b/crates/engine/src/cmd/geocode.rs
@@@ -1,0 -1,454 +1,472 @@@
+ //! Reverse geocoding (issue #582): fill City / State / Country from a photo's GPS position, offline, with the
+ //! GeoNames place names ([`lightcraft_geocode`]). The place names (CC-BY 4.0) are not shipped with the app: the user
+ //! downloads them once (`metadata.downloadPlaceNames`, ~3 MB from download.geonames.org) into the settings folder;
+ //! after that every lookup is local and no position ever leaves the machine.
+ //!
+ //! Sources: GeoNames dump readme (prose); own design.
+
+ use std::path::{Path, PathBuf};
+ use std::sync::{Arc, Mutex, PoisonError};
+ use std::time::SystemTime;
+
+ use serde_json::{Value, json};
+
+ use lightcraft_catalog::{Op, PhotoId};
+ use lightcraft_geocode::{GEONAMES_ATTRIBUTION, GEONAMES_FILES, GeoNames, LatLon};
+
+ use super::{CommandSpec, always, bad, bool_or, cmd, has_selection, str_param};
+ use crate::activity::Cancel;
+ use crate::{Result, Session};
+
+ /// Where the place names live: `dataset` (a folder) or `<settings>/geonames`.
+ fn dataset_dir(p: &Value) -> Option<PathBuf> {
+ str_param(p, "dataset").map(PathBuf::from).or_else(|| crate::config::config_dir().map(|d| d.join("geonames")))
+ }
+
+ /// How a place-names download ended.
+ #[derive(Clone, Debug, PartialEq)]
+ pub enum DownloadOutcome {
+ /// Done: this many places.
+ Done(usize),
+ /// Failed, in words the user can act on.
+ Failed(String),
+ Cancelled,
+ }
+
+ #[derive(Default)]
+ struct DownloadShared {
+ running: bool,
+ last: Option<DownloadOutcome>,
+ /// The last outcome, until the UI has shown it ([`PlaceNames::take_outcome`]).
+ unreported: Option<DownloadOutcome>,
+ }
+
+ /// The session's place names: the parsed gazetteer (kept while its file is unchanged) and the download state.
+ #[derive(Default)]
+ pub struct PlaceNames {
+ shared: Arc<Mutex<DownloadShared>>,
+ /// (cities file, its size, its modification time, the parsed names).
+ cache: Option<(PathBuf, u64, Option<SystemTime>, Arc<GeoNames>)>,
+ }
+
+ impl PlaceNames {
+ fn lock(&self) -> std::sync::MutexGuard<'_, DownloadShared> {
+ self.shared.lock().unwrap_or_else(PoisonError::into_inner)
+ }
+
+ /// A download that ended since the last call (the UI shows it once: an error stays readable as a toast).
+ pub fn take_outcome(&self) -> Option<DownloadOutcome> {
+ self.lock().unreported.take()
+ }
+
+ pub fn downloading(&self) -> bool {
+ self.lock().running
+ }
+
+ /// The gazetteer in `dir`, parsed once and re-read only when the cities file's size or time changes.
+ fn load(&mut self, dir: &Path) -> std::result::Result<Arc<GeoNames>, lightcraft_geocode::GeocodeError> {
+ let file = dir.join(GEONAMES_FILES[0]);
+ let meta = std::fs::metadata(&file).ok();
+ let (len, mtime) = (meta.as_ref().map_or(0, |m| m.len()), meta.as_ref().and_then(|m| m.modified().ok()));
+ if let Some((f, l, t, g)) = &self.cache
+ && meta.is_some()
+ && *f == file
+ && *l == len
+ && *t == mtime
+ {
+ return Ok(g.clone());
+ }
+ let g = Arc::new(GeoNames::load(dir)?);
+ self.cache = Some((file, len, mtime, g.clone()));
+ Ok(g)
+ }
+ }
+
+ fn status(s: &mut Session, p: &Value) -> Result<Value> {
+ let dir = dataset_dir(p);
+ let size = dir.as_ref().and_then(|d| std::fs::metadata(d.join(GEONAMES_FILES[0])).ok()).map(|m| m.len());
+ let sh = s.place_names.lock();
+ let (last, error) = match &sh.last {
+ None => (Value::Null, Value::Null),
+ Some(DownloadOutcome::Done(n)) => (json!({"places": n}), Value::Null),
+ Some(DownloadOutcome::Failed(e)) => (json!("failed"), json!(e)),
+ Some(DownloadOutcome::Cancelled) => (json!("cancelled"), Value::Null),
+ };
+ Ok(json!({
+ "downloaded": size.is_some(), "bytes": size, "path": dir, "downloading": sh.running, "lastDownload": last, "lastError": error,
+ "attribution": GEONAMES_ATTRIBUTION, "source": lightcraft_geocode::GEONAMES_BASE,
+ }))
+ }
+
+ /// Which place fields to write: a field is filled when it is empty, or always with `overwrite`.
+ fn fill(meta: &mut lightcraft_catalog::Meta, place: &lightcraft_geocode::Place, overwrite: bool) {
+ for (field, value) in [
+ (&mut meta.location, &place.sublocation),
+ (&mut meta.city, &place.city),
+ (&mut meta.state, &place.state),
+ (&mut meta.country, &place.country),
+ ] {
+ if !value.is_empty() && (overwrite || field.trim().is_empty()) {
+ *field = value.clone();
+ }
+ }
+ }
+
+ fn reverse(s: &mut Session, p: &Value) -> Result<Value> {
+ const C: &str = "metadata.reverseGeocode";
+ let overwrite = bool_or(p, "overwrite", false);
+ let ids = s.targets(p);
+ let todo: Vec<(PhotoId, LatLon)> = ids
+ .iter()
+ .filter_map(|id| {
+ let (la, lo) = s.catalog.photo(*id)?.meta.gps?;
+ let at = LatLon::new(la, lo);
+ at.is_valid().then_some((*id, at))
+ })
+ .collect();
+ if todo.is_empty() {
+ return Err(bad(C, "none of these photos has a GPS position"));
+ }
+ let dir = dataset_dir(p).ok_or_else(|| bad(C, "no settings folder: give `dataset`"))?;
+ let names = s.place_names.load(&dir).map_err(|e| bad(C, format!("{e}: download the place names first (Photo ▸ Download Place Names)")))?;
+ // a large selection shows in the activity stack and can be stopped
+ let task = (todo.len() > 1).then(|| s.activity.start("geocode", "Looking up places", Cancel::Yes));
+ let mut ops = Vec::new();
+ let mut found = Vec::new();
+ for (n, (id, at)) in todo.iter().enumerate() {
+ if let Some(t) = &task {
+ if t.cancel_flag().is_some_and(|f| f.load(std::sync::atomic::Ordering::Relaxed)) {
+ return Err(bad(C, "cancelled"));
+ }
+ t.progress(n as u64, todo.len() as u64);
+ }
+ let Some(place) = names.reverse(*at) else { continue };
+ let Some(ph) = s.catalog.photo(*id) else { continue };
+ let mut meta = ph.meta.clone();
+ fill(&mut meta, &place, overwrite);
+ if meta != ph.meta {
+ ops.push(Op::SetMeta { id: *id, meta: Box::new(meta) });
+ }
+ found.push(json!({"id": id.0, "place": place}));
+ }
+ drop(task);
+ let changed = ops.len();
+ if !bool_or(p, "dryRun", false) && changed > 0 {
+ s.commit("Reverse Geocode", Op::Batch { ops })?;
+ }
+ Ok(json!({"looked": todo.len(), "found": found.len(), "changed": changed, "photos": found, "attribution": GEONAMES_ATTRIBUTION}))
+ }
+
+ #[cfg(not(target_arch = "wasm32"))]
+ mod download {
+ use std::path::Path;
+ use std::sync::Arc;
+ use std::sync::atomic::AtomicBool;
+
+ use lightcraft_geocode::{GEONAMES_BASE, GEONAMES_ZIP};
+
+ use super::*;
+ use crate::activity::Unit;
+
+ const MAX_ZIP: u64 = 64 * 1024 * 1024;
+ const MAX_TEXT: usize = 256 * 1024 * 1024;
+
+ fn get(name: &str, base: &str, dir: &Path, cancel: &AtomicBool, task: &crate::activity::TaskHandle) -> std::result::Result<(), String> {
+ let _ = std::fs::remove_file(dir.join(name));
+ let file = lightcraft_fetch::FileSpec { name, size: None, sha256: None, max: MAX_ZIP };
+ lightcraft_fetch::download_url(&file, &format!("{base}{name}"), dir, &lightcraft_fetch::Options::default(), cancel, &mut |pr| {
+ task.progress(pr.done, pr.total.max(pr.done))
+ })
+ .map_err(|e| e.to_string())
+ }
+
+ /// Fetch and unpack the place names into `dir`; the new files replace the old ones only when complete.
+ pub(super) fn run(base: &str, dir: &Path, cancel: &AtomicBool, task: &crate::activity::TaskHandle) -> std::result::Result<usize, String> {
+ let staging = dir.join(".download");
+ std::fs::create_dir_all(&staging).map_err(|e| format!("could not create {}: {e}", staging.display()))?;
+ get(GEONAMES_ZIP, base, &staging, cancel, task)?;
+ let zip = std::fs::read(staging.join(GEONAMES_ZIP)).map_err(|e| e.to_string())?;
+ let cities = lightcraft_geocode::unzip::extract(&zip, GEONAMES_FILES[0], MAX_TEXT).map_err(|e| e.to_string())?;
+ let places = GeoNames::parse(&String::from_utf8_lossy(&cities), None, None).len();
+ if places == 0 {
+ return Err("the downloaded place list is empty".into());
+ }
+ let _ = std::fs::remove_file(staging.join(GEONAMES_ZIP));
+ let write = |name: &str, data: &[u8]| std::fs::write(dir.join(name), data).map_err(|e| format!("could not save {name}: {e}"));
+ for name in &GEONAMES_FILES[1..] {
+ // optional: without them states stay blank and countries are ISO codes
+ match get(name, base, &staging, cancel, task).and_then(|()| std::fs::read(staging.join(name)).map_err(|e| e.to_string())) {
+ Ok(b) => write(name, &b)?,
+ Err(e) => log::warn!("place names: {name}: {e}"),
+ }
+ let _ = std::fs::remove_file(staging.join(name));
+ }
+ write(GEONAMES_FILES[0], &cities)?;
+ let _ = std::fs::remove_dir(&staging);
+ Ok(places)
+ }
+
++ /// A download base: https, or plain http to this machine's loopback address only (a test
++ /// server), with nothing but a port or path after the host, so `http://127.0.0.1.example.com/`
++ /// is refused.
++ pub(super) fn base_allowed(base: &str) -> bool {
++ base.starts_with("https://")
++ || base.strip_prefix("http://127.0.0.1").is_some_and(|rest| rest.is_empty() || rest.starts_with(':') || rest.starts_with('/'))
++ }
++
+ /// `metadata.downloadPlaceNames`: starts a background download (shown in the activity stack, cancellable).
+ pub(super) fn start(s: &mut Session, p: &Value) -> Result<Value> {
+ const C: &str = "metadata.downloadPlaceNames";
+ let dir = dataset_dir(p).ok_or_else(|| bad(C, "no settings folder: give `dataset`"))?;
+ let base = str_param(p, "base").unwrap_or(GEONAMES_BASE).to_string();
- if !(base.starts_with("https://") || base.starts_with("http://127.0.0.1")) {
++ if !base_allowed(&base) {
+ return Err(bad(C, "`base` must be an https:// address"));
+ }
+ let shared = s.place_names.shared.clone();
+ {
+ let mut sh = s.place_names.lock();
+ if sh.running {
+ return Err(bad(C, "the place names are already downloading"));
+ }
+ sh.running = true;
+ }
+ let cancel = Arc::new(AtomicBool::new(false));
+ let task = s.activity.start("download", "Downloading place names", Cancel::Flag(cancel.clone()));
+ task.set_unit(Unit::Bytes);
+ task.detail("GeoNames");
+ let handle = task.handle();
+ let thread_dir = dir.clone();
+ let thread_shared = shared.clone();
+ let spawned = std::thread::Builder::new().name("place-names-download".into()).spawn(move || {
+ // the activity row goes when the thread ends, however it ends
+ let _task = task;
+ let outcome = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| run(&base, &thread_dir, &cancel, &handle)));
+ let outcome = match outcome {
+ Ok(Ok(n)) => DownloadOutcome::Done(n),
+ _ if cancel.load(std::sync::atomic::Ordering::Relaxed) => DownloadOutcome::Cancelled,
+ Ok(Err(e)) => DownloadOutcome::Failed(format!("Could not download the place names: {e}. Check the connection and try again.")),
+ Err(_) => DownloadOutcome::Failed("The place names download stopped unexpectedly. Try again.".into()),
+ };
+ if let DownloadOutcome::Failed(e) = &outcome {
+ log::warn!("{e}");
+ }
+ let mut sh = thread_shared.lock().unwrap_or_else(PoisonError::into_inner);
+ sh.running = false;
+ sh.last = Some(outcome.clone());
+ sh.unreported = Some(outcome);
+ });
+ if let Err(e) = spawned {
+ shared.lock().unwrap_or_else(PoisonError::into_inner).running = false;
+ return Err(bad(C, format!("could not start the download: {e}")));
+ }
+ Ok(json!({"started": true, "path": dir, "attribution": GEONAMES_ATTRIBUTION}))
+ }
+ }
+
+ pub fn specs() -> Vec<CommandSpec> {
+ #[allow(unused_mut)]
+ let mut v = vec![
+ cmd!(
+ "metadata.reverseGeocode",
+ "Fill Location from GPS",
+ ["Photo"],
+ None,
+ "{ids?, overwrite?: bool (also replace place fields that already have text; default false: only empty ones are filled), dryRun?, dataset?: folder} → {looked, found, changed, photos: [{id, place: {sublocation, city, state, country, iso, distance}}], attribution} — fills City / State / Country (and Sublocation when known) from GPS with the offline GeoNames place names (download them first); one undo step",
+ has_selection,
+ reverse
+ ),
+ cmd!(query "metadata.placeNamesStatus", "Place Names Status", [], None, "{dataset?: folder} → {downloaded, bytes, path, attribution, source}", always, status),
+ ];
+ #[cfg(not(target_arch = "wasm32"))]
+ v.push(cmd!(
+ "metadata.downloadPlaceNames",
+ "Download Place Names (GeoNames)",
+ ["Photo"],
+ None,
+ "{dataset?: folder} → {started, path, attribution} — downloads the GeoNames cities list (CC-BY 4.0, ~3 MB, from download.geonames.org) in the background for Fill Location from GPS; no photo data is sent",
+ always,
+ download::start
+ ));
+ v
+ }
+
+ #[cfg(test)]
+ mod tests {
+ use super::*;
+
+ const CITIES: &str = "2988507\tParis\tParis\t\t48.85341\t2.3488\tP\tPPLC\tFR\t\t11\t75\t\t\t2138551\t\t42\tEurope/Paris\t2024-01-01\n\
+ 2643743\tLondon\tLondon\t\t51.50853\t-0.12574\tP\tPPLC\tGB\t\tENG\t\t\t\t8961989\t\t25\tEurope/London\t2024-01-01\n";
+
+ fn dataset(tag: &str) -> PathBuf {
+ let dir = std::env::temp_dir().join(format!("lightcraft-geocode-cmd-{tag}-{}", std::process::id()));
+ let _ = std::fs::remove_dir_all(&dir);
+ std::fs::create_dir_all(&dir).unwrap();
+ std::fs::write(dir.join(GEONAMES_FILES[0]), CITIES).unwrap();
+ std::fs::write(dir.join(GEONAMES_FILES[1]), "FR.11\tÎle-de-France\nGB.ENG\tEngland\n").unwrap();
+ std::fs::write(dir.join(GEONAMES_FILES[2]), "#c\nFR\tFRA\t250\tFR\tFrance\nGB\tGBR\t826\tUK\tUnited Kingdom\n").unwrap();
+ dir
+ }
+
+ fn set_gps(s: &mut Session, id: PhotoId, gps: Option<(f64, f64)>, city: &str) {
+ let mut meta = s.catalog.photo(id).unwrap().meta.clone();
+ meta.gps = gps;
+ meta.city = city.into();
+ meta.state.clear();
+ meta.country.clear();
+ meta.location.clear();
+ s.commit("test", Op::SetMeta { id, meta: Box::new(meta) }).unwrap();
+ }
+
+ #[test]
+ fn fills_empty_fields_keeps_typed_ones_and_undoes() {
+ let mut s = Session::with_demo();
+ let ids = s.visible_cloned();
+ let dir = dataset("fill");
+ set_gps(&mut s, ids[0], Some((48.86, 2.34)), "");
+ set_gps(&mut s, ids[1], Some((51.5, -0.1)), "Westminster");
+ set_gps(&mut s, ids[2], Some((f64::NAN, 0.0)), "");
+ set_gps(&mut s, ids[3], Some((0.0, 0.0)), "");
+ let r = s.execute("metadata.reverseGeocode", &json!({"ids": [ids[0].0, ids[1].0, ids[2].0, ids[3].0], "dataset": dir})).unwrap();
+ assert_eq!((r["looked"].as_u64(), r["found"].as_u64(), r["changed"].as_u64()), (Some(3), Some(2), Some(2)), "{r}");
+ let m0 = s.catalog.photo(ids[0]).unwrap().meta.clone();
+ assert_eq!((m0.city.as_str(), m0.state.as_str(), m0.country.as_str()), ("Paris", "Île-de-France", "France"));
+ let m1 = s.catalog.photo(ids[1]).unwrap().meta.clone();
+ assert_eq!((m1.city.as_str(), m1.state.as_str(), m1.country.as_str()), ("Westminster", "England", "United Kingdom"));
+ assert!(s.activity.list().is_empty(), "the activity row ends with the command");
+ // one undo step
+ s.undo_step().unwrap();
+ assert!(s.catalog.photo(ids[0]).unwrap().meta.city.is_empty());
+ assert_eq!(s.catalog.photo(ids[1]).unwrap().meta.city, "Westminster");
+ // overwrite replaces typed text
+ s.execute("metadata.reverseGeocode", &json!({"ids": [ids[1].0], "dataset": dir, "overwrite": true})).unwrap();
+ assert_eq!(s.catalog.photo(ids[1]).unwrap().meta.city, "London");
+ let _ = std::fs::remove_dir_all(&dir);
+ }
+
+ #[test]
+ fn explains_missing_data_and_gps() {
+ let mut s = Session::with_demo();
+ let ids = s.visible_cloned();
+ set_gps(&mut s, ids[0], None, "");
+ let e = s.execute("metadata.reverseGeocode", &json!({"ids": [ids[0].0]})).unwrap_err();
+ assert!(e.to_string().contains("GPS"), "{e}");
+ set_gps(&mut s, ids[0], Some((48.86, 2.34)), "");
+ let missing = std::env::temp_dir().join(format!("lightcraft-geocode-none-{}", std::process::id()));
+ let e = s.execute("metadata.reverseGeocode", &json!({"ids": [ids[0].0], "dataset": missing})).unwrap_err();
+ assert!(e.to_string().contains("download"), "{e}");
+ let st = s.execute("metadata.placeNamesStatus", &json!({"dataset": missing})).unwrap();
+ assert_eq!(st["downloaded"], false);
+ }
+
+ #[test]
+ fn the_gazetteer_is_cached_until_its_file_changes() {
+ let dir = dataset("cache");
+ let mut names = PlaceNames::default();
+ let a = names.load(&dir).unwrap();
+ assert!(Arc::ptr_eq(&a, &names.load(&dir).unwrap()), "unchanged file: no re-read");
+ // a different size invalidates it (a new download)
+ std::fs::write(dir.join(GEONAMES_FILES[0]), "1\tRome\tRome\t\t41.9\t12.5\tP\tP\tIT\t\t07\n").unwrap();
+ let b = names.load(&dir).unwrap();
+ assert!(!Arc::ptr_eq(&a, &b));
+ assert_eq!(b.reverse(LatLon::new(41.9, 12.5)).unwrap().city, "Rome");
+ std::fs::remove_file(dir.join(GEONAMES_FILES[0])).unwrap();
+ assert!(names.load(&dir).is_err(), "a deleted file is not served from the cache");
+ let _ = std::fs::remove_dir_all(&dir);
+ }
+
+ /// A local HTTP server; the first path segment picks the behaviour: `good` (the synthetic dump), `garbage` (a zip
+ /// that isn't one), `short` (the body ends before its Content-Length), anything else 404.
+ #[cfg(not(target_arch = "wasm32"))]
+ fn serve() -> String {
+ use std::io::{BufRead, BufReader, Write};
+ let l = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
+ let port = l.local_addr().unwrap().port();
+ let zip = lightcraft_geocode::unzip::make(GEONAMES_FILES[0], CITIES.as_bytes());
+ std::thread::spawn(move || {
+ for conn in l.incoming() {
+ let Ok(mut c) = conn else { continue };
+ let mut r = BufReader::new(c.try_clone().unwrap());
+ let mut line = String::new();
+ let _ = r.read_line(&mut line);
+ loop {
+ let mut h = String::new();
+ if r.read_line(&mut h).unwrap_or(0) == 0 || h.trim().is_empty() {
+ break;
+ }
+ }
+ let path = line.split(' ').nth(1).unwrap_or("").to_string();
+ let (status, body, len): (&str, Vec<u8>, Option<usize>) = match (path.split('/').nth(1).unwrap_or(""), path.ends_with(".zip")) {
+ ("good", true) => ("200 OK", zip.clone(), None),
+ ("good", false) if path.contains("countryInfo") => ("200 OK", b"FR\tFRA\t250\tFR\tFrance\n".to_vec(), None),
+ ("garbage", true) => ("200 OK", b"<html>not a zip</html>".to_vec(), None),
+ ("short", true) => ("200 OK", zip[..zip.len() / 2].to_vec(), Some(zip.len())),
+ _ => ("404 Not Found", b"nope".to_vec(), None),
+ };
+ let n = len.unwrap_or(body.len());
+ let _ = c.write_all(format!("HTTP/1.1 {status}\r\nContent-Length: {n}\r\nConnection: close\r\n\r\n").as_bytes());
+ let _ = c.write_all(&body);
+ }
+ });
+ format!("http://127.0.0.1:{port}")
+ }
+
+ #[cfg(not(target_arch = "wasm32"))]
+ fn download(s: &mut Session, base: &str, dir: &Path) -> DownloadOutcome {
+ s.execute("metadata.downloadPlaceNames", &json!({"dataset": dir, "base": base})).unwrap();
+ assert!(s.place_names.downloading() || s.place_names.lock().unreported.is_some());
+ let started = std::time::Instant::now();
+ loop {
+ if let Some(o) = s.place_names.take_outcome() {
+ // the activity row ends with the thread
+ while !s.activity.list().is_empty() && started.elapsed().as_secs() < 30 {
+ std::thread::sleep(std::time::Duration::from_millis(10));
+ }
+ assert!(s.activity.list().is_empty());
+ return o;
+ }
+ assert!(started.elapsed().as_secs() < 60, "the download never ended");
+ std::thread::sleep(std::time::Duration::from_millis(10));
+ }
+ }
+
+ #[cfg(not(target_arch = "wasm32"))]
+ #[test]
+ fn download_end_to_end_and_its_failures() {
+ let mut s = Session::with_demo();
+ let ids = s.visible_cloned();
+ let base = serve();
+ let dir = std::env::temp_dir().join(format!("lightcraft-geocode-dl-{}", std::process::id()));
+ let _ = std::fs::remove_dir_all(&dir);
+ assert!(s.execute("metadata.downloadPlaceNames", &json!({"dataset": dir, "base": "http://example.com/"})).is_err());
+
+ for bad in ["missing", "garbage", "short"] {
+ let o = download(&mut s, &format!("{base}/{bad}/"), &dir);
+ let DownloadOutcome::Failed(e) = o else { panic!("{bad}: {o:?}") };
+ assert!(e.contains("try again"), "{bad}: {e}");
+ let st = s.execute("metadata.placeNamesStatus", &json!({"dataset": dir})).unwrap();
+ assert_eq!((st["downloaded"].as_bool(), st["lastDownload"].as_str()), (Some(false), Some("failed")), "{bad}: {st}");
+ assert_eq!(st["lastError"].as_str(), Some(e.as_str()));
+ assert!(s.place_names.take_outcome().is_none(), "reported once");
+ }
+
+ assert_eq!(download(&mut s, &format!("{base}/good/"), &dir), DownloadOutcome::Done(2));
+ let st = s.execute("metadata.placeNamesStatus", &json!({"dataset": dir})).unwrap();
+ assert_eq!((st["downloaded"].as_bool(), st["lastError"].is_null(), st["lastDownload"]["places"].as_u64()), (Some(true), true, Some(2)));
+ set_gps(&mut s, ids[0], Some((48.86, 2.34)), "");
+ s.execute("metadata.reverseGeocode", &json!({"ids": [ids[0].0], "dataset": dir})).unwrap();
+ let m = s.catalog.photo(ids[0]).unwrap().meta.clone();
+ // admin1 was a 404 (optional): the state stays blank, the rest is filled
+ assert_eq!((m.city.as_str(), m.state.as_str(), m.country.as_str()), ("Paris", "", "France"));
+ let _ = std::fs::remove_dir_all(&dir);
+ }
++
++ #[test]
++ fn download_base_is_https_or_loopback_only() {
++ assert!(download::base_allowed("https://download.geonames.org/export/dump/"));
++ assert!(download::base_allowed("http://127.0.0.1:8080"));
++ assert!(download::base_allowed("http://127.0.0.1/dump"));
++ assert!(!download::base_allowed("http://127.0.0.1.example.com/"));
++ assert!(!download::base_allowed("http://[email protected]/"));
++ assert!(!download::base_allowed("http://download.geonames.org/"));
++ }
+ }
diff --cc crates/ui-egui/locales/de.json
index 6d9ae32a6,4d511be64..5c62067d0
--- a/crates/ui-egui/locales/de.json
+++ b/crates/ui-egui/locales/de.json
@@@ -2045,8 -2040,13 +2045,17 @@@
"Finding faces": "Gesichter werden gesucht",
"Synchronizing folder": "Ordner wird synchronisiert",
"Looking for changes": "Änderungen werden gesucht",
+ "This is a Lightroom catalog, not a LightCraft library. Import it into a LightCraft library instead?": "Dies ist ein Lightroom-Katalog, keine LightCraft-Bibliothek. Stattdessen in eine LightCraft-Bibliothek importieren?",
+ "The import reads the catalog without changing it and adds its photos, edits, keywords and collections to the library open now.": "Der Import liest den Katalog, ohne ihn zu ändern, und fügt seine Fotos, Bearbeitungen, Stichwörter und Sammlungen der jetzt geöffneten Bibliothek hinzu.",
+ "Albums hold library photos: Add to My Photos first": "Alben enthalten Bibliotheksfotos: zuerst zu „Meine Fotos“ hinzufügen",
- "Add to My Photos First": "Zuerst zu „Meine Fotos“ hinzufügen"
++ "Add to My Photos First": "Zuerst zu „Meine Fotos“ hinzufügen",
+ "Fill Location from GPS": "Ort aus GPS ausfüllen",
+ "Download Place Names (GeoNames)": "Ortsnamen herunterladen (GeoNames)",
+ "Place Names Status": "Status der Ortsnamen",
+ "Fill Location": "Ort ausfüllen",
+ "Fill empty City, State and Country from GPS (offline GeoNames place names)": "Leere Felder Stadt, Bundesland und Land aus GPS ausfüllen (GeoNames-Ortsnamen, offline)",
+ "Looking up places": "Orte werden nachgeschlagen",
+ "Downloading place names": "Ortsnamen werden heruntergeladen",
+ "Place names downloaded": "Ortsnamen heruntergeladen",
+ "Place names download cancelled": "Download der Ortsnamen abgebrochen"
}
diff --cc crates/ui-egui/locales/es.json
index 93851ff77,3c6285419..24a6797d2
--- a/crates/ui-egui/locales/es.json
+++ b/crates/ui-egui/locales/es.json
@@@ -1890,8 -1885,13 +1890,17 @@@
"Finding faces": "Buscando caras",
"Synchronizing folder": "Sincronizando carpeta",
"Looking for changes": "Buscando cambios",
+ "This is a Lightroom catalog, not a LightCraft library. Import it into a LightCraft library instead?": "Esto es un catálogo de Lightroom, no una biblioteca de LightCraft. ¿Importarlo a una biblioteca de LightCraft?",
+ "The import reads the catalog without changing it and adds its photos, edits, keywords and collections to the library open now.": "La importación lee el catálogo sin modificarlo y añade sus fotos, ediciones, palabras clave y colecciones a la biblioteca abierta ahora.",
+ "Albums hold library photos: Add to My Photos first": "Los álbumes contienen fotos de la biblioteca: añádelas primero a Mis fotos",
- "Add to My Photos First": "Añadir primero a Mis fotos"
++ "Add to My Photos First": "Añadir primero a Mis fotos",
+ "Fill Location from GPS": "Rellenar ubicación desde GPS",
+ "Download Place Names (GeoNames)": "Descargar nombres de lugares (GeoNames)",
+ "Place Names Status": "Estado de los nombres de lugares",
+ "Fill Location": "Rellenar ubicación",
+ "Fill empty City, State and Country from GPS (offline GeoNames place names)": "Rellenar Ciudad, Estado y País vacíos desde el GPS (nombres de lugares de GeoNames, sin conexión)",
+ "Looking up places": "Buscando lugares",
+ "Downloading place names": "Descargando nombres de lugares",
+ "Place names downloaded": "Nombres de lugares descargados",
+ "Place names download cancelled": "Descarga de nombres de lugares cancelada"
}
diff --cc crates/ui-egui/locales/fr.json
index 0ceef366e,053df242a..ed6c0084a
--- a/crates/ui-egui/locales/fr.json
+++ b/crates/ui-egui/locales/fr.json
@@@ -1890,8 -1885,13 +1890,17 @@@
"Reset Panel Layout": "Reset Panel Layout",
"Resize panel window": "Resize panel window",
"Resize panels": "Resize panels",
+ "This is a Lightroom catalog, not a LightCraft library. Import it into a LightCraft library instead?": "Ceci est un catalogue Lightroom, pas une bibliothèque LightCraft. L’importer plutôt dans une bibliothèque LightCraft ?",
+ "The import reads the catalog without changing it and adds its photos, edits, keywords and collections to the library open now.": "L’importation lit le catalogue sans le modifier et ajoute ses photos, retouches, mots-clés et collections à la bibliothèque ouverte.",
+ "Albums hold library photos: Add to My Photos first": "Les albums contiennent des photos de la bibliothèque : ajoutez-les d’abord à Mes photos",
- "Add to My Photos First": "Ajouter d’abord à Mes photos"
++ "Add to My Photos First": "Ajouter d’abord à Mes photos",
+ "Fill Location from GPS": "Remplir le lieu depuis le GPS",
+ "Download Place Names (GeoNames)": "Télécharger les noms de lieux (GeoNames)",
+ "Place Names Status": "État des noms de lieux",
+ "Fill Location": "Remplir le lieu",
+ "Fill empty City, State and Country from GPS (offline GeoNames place names)": "Remplir Ville, État et Pays vides depuis le GPS (noms de lieux GeoNames, hors ligne)",
+ "Looking up places": "Recherche des lieux",
+ "Downloading place names": "Téléchargement des noms de lieux",
+ "Place names downloaded": "Noms de lieux téléchargés",
+ "Place names download cancelled": "Téléchargement des noms de lieux annulé"
}
diff --cc crates/ui-egui/locales/ja.json
index 3d92a8351,916bdc50c..6f0ea5f30
--- a/crates/ui-egui/locales/ja.json
+++ b/crates/ui-egui/locales/ja.json
@@@ -1892,8 -1887,13 +1892,17 @@@
"Finding faces": "顔を検索中",
"Synchronizing folder": "フォルダを同期中",
"Looking for changes": "変更を確認中",
+ "This is a Lightroom catalog, not a LightCraft library. Import it into a LightCraft library instead?": "これは Lightroom カタログで、LightCraft ライブラリではありません。代わりに LightCraft ライブラリに読み込みますか?",
+ "The import reads the catalog without changing it and adds its photos, edits, keywords and collections to the library open now.": "読み込みはカタログを変更せずに読み取り、写真・編集・キーワード・コレクションを現在開いているライブラリに追加します。",
+ "Albums hold library photos: Add to My Photos first": "アルバムに入れられるのはライブラリの写真です:先にマイフォトに追加してください",
- "Add to My Photos First": "先にマイフォトに追加"
++ "Add to My Photos First": "先にマイフォトに追加",
+ "Fill Location from GPS": "GPS から場所を入力",
+ "Download Place Names (GeoNames)": "地名データをダウンロード (GeoNames)",
+ "Place Names Status": "地名データの状態",
+ "Fill Location": "場所を入力",
+ "Fill empty City, State and Country from GPS (offline GeoNames place names)": "空の市区町村・都道府県・国を GPS から入力 (GeoNames の地名、オフライン)",
+ "Looking up places": "場所を検索中",
+ "Downloading place names": "地名データをダウンロード中",
+ "Place names downloaded": "地名データをダウンロードしました",
+ "Place names download cancelled": "地名データのダウンロードを中止しました"
}
diff --cc crates/ui-egui/locales/pt-br.json
index 189b994c6,2ae5f108d..648a93855
--- a/crates/ui-egui/locales/pt-br.json
+++ b/crates/ui-egui/locales/pt-br.json
@@@ -1890,8 -1885,13 +1890,17 @@@
"Finding faces": "Procurando rostos",
"Synchronizing folder": "Sincronizando pasta",
"Looking for changes": "Procurando alterações",
+ "This is a Lightroom catalog, not a LightCraft library. Import it into a LightCraft library instead?": "Este é um catálogo do Lightroom, não uma biblioteca do LightCraft. Importá-lo para uma biblioteca do LightCraft?",
+ "The import reads the catalog without changing it and adds its photos, edits, keywords and collections to the library open now.": "A importação lê o catálogo sem alterá-lo e adiciona as fotos, edições, palavras-chave e coleções dele à biblioteca aberta agora.",
+ "Albums hold library photos: Add to My Photos first": "Álbuns contêm fotos da biblioteca: adicione-as às Minhas fotos primeiro",
- "Add to My Photos First": "Adicionar às Minhas fotos primeiro"
++ "Add to My Photos First": "Adicionar às Minhas fotos primeiro",
+ "Fill Location from GPS": "Preencher local pelo GPS",
+ "Download Place Names (GeoNames)": "Baixar nomes de lugares (GeoNames)",
+ "Place Names Status": "Status dos nomes de lugares",
+ "Fill Location": "Preencher local",
+ "Fill empty City, State and Country from GPS (offline GeoNames place names)": "Preencher Cidade, Estado e País vazios pelo GPS (nomes de lugares GeoNames, offline)",
+ "Looking up places": "Procurando lugares",
+ "Downloading place names": "Baixando nomes de lugares",
+ "Place names downloaded": "Nomes de lugares baixados",
+ "Place names download cancelled": "Download dos nomes de lugares cancelado"
}
diff --cc crates/ui-egui/locales/ru.json
index 62025ff35,562b1c6f3..c38029ef5
--- a/crates/ui-egui/locales/ru.json
+++ b/crates/ui-egui/locales/ru.json
@@@ -1604,8 -1599,13 +1604,17 @@@
"Quit Anyway": "Всё равно выйти",
"Synchronizing folder": "Синхронизация папки",
"Looking for changes": "Поиск изменений",
+ "This is a Lightroom catalog, not a LightCraft library. Import it into a LightCraft library instead?": "Это каталог Lightroom, а не библиотека LightCraft. Импортировать его в библиотеку LightCraft?",
+ "The import reads the catalog without changing it and adds its photos, edits, keywords and collections to the library open now.": "Импорт читает каталог, не изменяя его, и добавляет его фото, правки, ключевые слова и коллекции в открытую сейчас библиотеку.",
+ "Albums hold library photos: Add to My Photos first": "В альбомах только фото из библиотеки: сначала добавьте их в «Мои фото»",
- "Add to My Photos First": "Сначала добавить в «Мои фото»"
++ "Add to My Photos First": "Сначала добавить в «Мои фото»",
+ "Fill Location from GPS": "Заполнить место по GPS",
+ "Download Place Names (GeoNames)": "Загрузить названия мест (GeoNames)",
+ "Place Names Status": "Состояние названий мест",
+ "Fill Location": "Заполнить место",
+ "Fill empty City, State and Country from GPS (offline GeoNames place names)": "Заполнить пустые поля «Город», «Регион» и «Страна» по GPS (названия мест GeoNames, офлайн)",
+ "Looking up places": "Поиск мест",
+ "Downloading place names": "Загрузка названий мест",
+ "Place names downloaded": "Названия мест загружены",
+ "Place names download cancelled": "Загрузка названий мест отменена"
}
diff --cc crates/ui-egui/locales/uk.json
index 45852693f,fd506d14c..45559669a
--- a/crates/ui-egui/locales/uk.json
+++ b/crates/ui-egui/locales/uk.json
@@@ -2084,8 -2079,13 +2084,17 @@@
"Reset Panel Layout": "Reset Panel Layout",
"Resize panel window": "Resize panel window",
"Resize panels": "Resize panels",
+ "This is a Lightroom catalog, not a LightCraft library. Import it into a LightCraft library instead?": "Це каталог Lightroom, а не бібліотека LightCraft. Імпортувати його до бібліотеки LightCraft?",
+ "The import reads the catalog without changing it and adds its photos, edits, keywords and collections to the library open now.": "Імпорт читає каталог, не змінюючи його, і додає його фото, редагування, ключові слова та колекції до відкритої зараз бібліотеки.",
+ "Albums hold library photos: Add to My Photos first": "В альбомах лише фото з бібліотеки: спершу додайте їх до моїх фото",
- "Add to My Photos First": "Спершу додати до моїх фото"
++ "Add to My Photos First": "Спершу додати до моїх фото",
+ "Fill Location from GPS": "Заповнити місце за GPS",
+ "Download Place Names (GeoNames)": "Завантажити назви місць (GeoNames)",
+ "Place Names Status": "Стан назв місць",
+ "Fill Location": "Заповнити місце",
+ "Fill empty City, State and Country from GPS (offline GeoNames place names)": "Заповнити порожні поля «Місто», «Регіон» і «Країна» за GPS (назви місць GeoNames, офлайн)",
+ "Looking up places": "Пошук місць",
+ "Downloading place names": "Завантаження назв місць",
+ "Place names downloaded": "Назви місць завантажено",
+ "Place names download cancelled": "Завантаження назв місць скасовано"
}
diff --cc crates/ui-egui/locales/zh-hans.json
index 9d2165cd9,2ae6e716b..bd653c085
--- a/crates/ui-egui/locales/zh-hans.json
+++ b/crates/ui-egui/locales/zh-hans.json
@@@ -1890,8 -1885,13 +1890,17 @@@
"Finding faces": "正在查找人脸",
"Synchronizing folder": "正在同步文件夹",
"Looking for changes": "正在查找更改",
+ "This is a Lightroom catalog, not a LightCraft library. Import it into a LightCraft library instead?": "这是 Lightroom 目录,不是 LightCraft 图库。要改为将其导入 LightCraft 图库吗?",
+ "The import reads the catalog without changing it and adds its photos, edits, keywords and collections to the library open now.": "导入只读取目录、不做任何更改,并将其中的照片、编辑、关键字和收藏夹添加到当前打开的图库。",
+ "Albums hold library photos: Add to My Photos first": "相册只能收录图库中的照片:请先添加到我的照片",
- "Add to My Photos First": "先添加到我的照片"
++ "Add to My Photos First": "先添加到我的照片",
+ "Fill Location from GPS": "根据 GPS 填写位置",
+ "Download Place Names (GeoNames)": "下载地名数据 (GeoNames)",
+ "Place Names Status": "地名数据状态",
+ "Fill Location": "填写位置",
+ "Fill empty City, State and Country from GPS (offline GeoNames place names)": "根据 GPS 填写空白的城市、省/州和国家(GeoNames 地名,离线)",
+ "Looking up places": "正在查找地点",
+ "Downloading place names": "正在下载地名数据",
+ "Place names downloaded": "地名数据已下载",
+ "Place names download cancelled": "已取消下载地名数据"
}
diff --cc crates/ui-egui/locales/zh-hant.json
index fa951faa2,bf651fc68..e1e274c54
--- a/crates/ui-egui/locales/zh-hant.json
+++ b/crates/ui-egui/locales/zh-hant.json
@@@ -1890,8 -1885,13 +1890,17 @@@
"Finding faces": "正在尋找臉孔",
"Synchronizing folder": "正在同步資料夾",
"Looking for changes": "正在尋找變更",
+ "This is a Lightroom catalog, not a LightCraft library. Import it into a LightCraft library instead?": "這是 Lightroom 目錄,不是 LightCraft 照片庫。要改為將其匯入 LightCraft 照片庫嗎?",
+ "The import reads the catalog without changing it and adds its photos, edits, keywords and collections to the library open now.": "匯入只讀取目錄、不做任何變更,並將其中的照片、編輯、關鍵字和收藏夾加入目前開啟的照片庫。",
+ "Albums hold library photos: Add to My Photos first": "相簿只能收錄圖庫中的照片:請先加入我的照片",
- "Add to My Photos First": "先加入我的照片"
++ "Add to My Photos First": "先加入我的照片",
+ "Fill Location from GPS": "根據 GPS 填寫位置",
+ "Download Place Names (GeoNames)": "下載地名資料 (GeoNames)",
+ "Place Names Status": "地名資料狀態",
+ "Fill Location": "填寫位置",
+ "Fill empty City, State and Country from GPS (offline GeoNames place names)": "根據 GPS 填寫空白的城市、州/省和國家(GeoNames 地名,離線)",
+ "Looking up places": "正在查找地點",
+ "Downloading place names": "正在下載地名資料",
+ "Place names downloaded": "地名資料已下載",
+ "Place names download cancelled": "已取消下載地名資料"
}
diff --cc docs/parity-checklist.md
index 70598f196,aac80c529..6ed5b23b3
--- a/docs/parity-checklist.md
+++ b/docs/parity-checklist.md
@@@ -164,9 -164,9 +164,9 @@@ differences and missing bindings are i
|---|---|---|---|---|---|
| LR-META-INFO | Info panel | P0 | ✅ | `cmd:panel.info`, `cmd:photo.setMeta`, `crates/ui-egui/src/panels/right.rs` (`info`, `camera_card`) | camera card (camera, lens, size, format, focal length / shutter / aperture / ISO); title, caption, alt text, extended description, copyright, copyright status, rights usage terms, copyright info URL, creator; file name (rename), file path (reveal), capture time (edit); location, city, state, country; GPS. No flash, map snippet or people |
| LR-META-COPYRIGHT-DEFAULT | Default copyright on import | P1 | ✅ | `cmd:library.preferences` (`import.copyright`, `import.creator`), `crates/ui-egui/src/panels/settings.rs` | Settings → Import → Metadata; fills only photos without their own |
- | LR-META-LOCATION | Location editing | P2 | 🟡 | `cmd:photo.setMeta` (`location`, `city`, `state`, `country`, `gps`) | place fields and GPS (decimal or degrees / minutes / seconds) edited in Info, read/written as IPTC Core / Photoshop / EXIF XMP; Show on Map opens OpenStreetMap; no embedded map, no geocoding |
+ | LR-META-LOCATION | Location editing | P2 | 🟡 | `cmd:photo.setMeta` (`location`, `city`, `state`, `country`, `gps`), `cmd:metadata.reverseGeocode` | place fields and GPS (decimal or degrees / minutes / seconds) edited in Info, read/written as IPTC Core / Photoshop / EXIF XMP; Show on Map opens OpenStreetMap; Fill Location fills empty City / State / Country from GPS offline (GeoNames, downloaded on request: `cmd:metadata.downloadPlaceNames`); no embedded map |
| LR-META-COPYPASTE | Copy / paste metadata | P2 | ✅ | `cmd:photo.copyMetadata`, `cmd:photo.pasteMetadata` | title, caption, alt text, extended description, copyright (notice, status, usage terms, info URL), creator, place fields, keywords; `fields` picks a subset |
-| LR-META-XMP | XMP read/write | P0 | ✅ | `cmd:photo.saveMetadataToFile`, `cmd:photo.readMetadataFromFile`, `cmd:library.xmpPreferences`, `crates/engine/src/sidecar.rs`, `docs/xmp-interop.md` | sidecar wins for metadata; a sidecar capture time (`exif:DateTimeOriginal` / `photoshop:DateCreated` / `xmp:CreateDate`) fills in only when the file has none; saving merges into an existing sidecar (`crates/meta/src/xmp_merge.rs`): another app's `crs:`, `xmpMM:History` and unknown namespaces are kept byte for byte, an unreadable sidecar is backed up first; with stem naming, files sharing a stem (raw + JPEG) get separate sidecars (`<file>.xmp` for all but the raw); a `crs:` custom white balance on a relative-WB raw is shifted from `crs:AsShotTemperature` rather than read as Kelvin, or kept As Shot and reported when the packet has no as-shot white (issue #510) |
+| LR-META-XMP | XMP read/write | P0 | ✅ | `cmd:photo.saveMetadataToFile`, `cmd:photo.readMetadataFromFile`, `cmd:library.xmpPreferences`, `crates/engine/src/sidecar.rs`, `docs/xmp-interop.md` | sidecar wins for metadata; a sidecar capture time (`exif:DateTimeOriginal` / `photoshop:DateCreated` / `xmp:CreateDate`) fills in only when the file has none; saving merges into an existing sidecar (`crates/meta/src/xmp_merge.rs`): another app's `crs:`, `xmpMM:History` and unknown namespaces are kept byte for byte, an unreadable sidecar is backed up first; with stem naming, files sharing a stem (raw + JPEG) get separate sidecars (`<file>.xmp` for all but the raw); a `crs:` custom white balance on a relative-WB raw is shifted from `crs:AsShotTemperature` rather than read as Kelvin, or kept As Shot and reported when the packet has no as-shot white (issue #510); heal and clone spots (`crs:RetouchAreas`, legacy `crs:RetouchInfo`) are read into our spots (`crates/engine/src/crs_masks.rs`, see `docs/xmp-interop.md` → Spot removal) |
| LR-META-EXIF-FULL | Full EXIF/IPTC [Classic] | P1 | ✅ | `cmd:photo.allMetadata`, `cmd:dialog.allMetadata`, `crates/meta/src/tags.rs`, `crates/meta/src/exif.rs`, `crates/meta/src/iptc.rs` | read and written on export; Info ▸ All Metadata…: every TIFF / EXIF / GPS / interop tag (named, common values spelled out) and the XMP fields, searchable; metadata presets |
## F. Edit panel — global adjustments (EDIT)