Cotton code
73 lines · 2.9 KB · RustRaw
//! The Apple Photos library, as a source.//!//! **Filesystem-only, and no `PHPhotoLibrary` anywhere** (design M7): the app//! reads the library's own SQLite the way osxphotos does, so there is no//! authorization prompt to ask for and no framework to hold the answer. What//! stands in the way is Full Disk Access, which cannot be requested//! programmatically and never will be — so it is a STATE the panel draws a//! button for, not an error anything retries against.pub mod apple;/// The synthetic library every test in this module reads. Nothing real ever/// goes in this tree.#[cfg(test)]pub(crate) mod fixture;pub mod library;pub mod source;pub use source::{PhotosSource, ASSETS_PER_BATCH};use std::collections::BTreeMap;use std::path::PathBuf;use serde::{Deserialize, Serialize};use apple::{AppleAssetRow, AppleFaceRow, ApplePersonRow, PlaceReading};/// One asset, with everything the applier needs that the person's own file/// cannot supply.////// The reader reads; the applier decides. So the place reading and the faces/// travel WITH the row rather than being fetched again behind the applier —/// there is one open handle on the library copy and it belongs to the reader.#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct PhotoAsset {    pub row: AppleAssetRow,    pub place: PlaceReading,    pub faces: Vec<AppleFaceRow>,    /// The original's sha256, once something has hashed the bytes: the Mac's    /// importer fills it as it puts the original under    /// `<database id>/photos/<sha256>.<ext>`, and the object names that key on    /// the row. The reader never reads a picture, so it leaves this empty.    #[serde(default)]    pub sha256: Option<String>,}/// One cluster of faces Photos has grouped, as the reader resolved it.////// `person` is the row at the END of the merge chain — Photos merges by/// pointing one cluster at another rather than by rewriting the faces, so the/// face still names the cluster it was found in and following the chain here is/// what stops one person becoming two.#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct PhotoCluster {    pub person: ApplePersonRow,    /// The Contacts card Photos matched, when it matched one.    pub contact_identifier: Option<String>,}/// One page of the library, as the reader read it.#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct PhotoWork {    /// The library's own directory. A library-relative original hangs off it,    /// and it is the LIVE library rather than the copy: the copy holds the    /// databases and none of the pictures.    #[serde(rename = "library")]    pub library_path: PathBuf,    pub assets: Vec<PhotoAsset>,    /// Every cluster a face in this page names, keyed by the cluster's uuid.    pub clusters: BTreeMap<String, PhotoCluster>,}