Skip to main content

syncweb_core/
pins.rs

1//! Centralized blob pin-name formatting.
2//!
3//! Every retention pin is a named tag in the blob store. Names are built from
4//! the shared prefixes in [`crate::constants`] plus the entity's identifiers so
5//! garbage collection can tell public shares, collections, snapshots, and
6//! one-off downloads apart. Formatting lives here so the wire-level naming
7//! convention is defined in one place.
8
9use iroh_blobs::Hash;
10use iroh_docs::NamespaceId;
11use uuid::Uuid;
12
13use crate::constants::{
14    COLLECTION_MANIFEST_PIN_PREFIX, COLLECTION_PIN_PREFIX, DOWNLOAD_PIN_PREFIX, PUBLIC_PIN_PREFIX,
15    SNAPSHOT_PIN_PREFIX,
16};
17
18/// Pin name for a publicly shared folder blob.
19#[must_use]
20pub fn public_blob_pin(namespace_id: NamespaceId, hash: Hash) -> String {
21    format!("{PUBLIC_PIN_PREFIX}{namespace_id}/{hash}")
22}
23
24/// Pin name for a published collection manifest blob.
25#[must_use]
26pub fn collection_manifest_pin(hash: Hash) -> String {
27    format!("{COLLECTION_MANIFEST_PIN_PREFIX}{hash}")
28}
29
30/// Pin name for a content blob referenced by a published collection.
31#[must_use]
32pub fn collection_content_pin(collection_id: Uuid, hash: Hash) -> String {
33    format!("{COLLECTION_PIN_PREFIX}{collection_id}/{hash}")
34}
35
36/// Pin name for a snapshot manifest blob.
37#[must_use]
38pub fn snapshot_manifest_pin(id: Hash) -> String {
39    format!("{SNAPSHOT_PIN_PREFIX}{id}/manifest")
40}
41
42/// Pin name for a content blob referenced by a snapshot.
43#[must_use]
44pub fn snapshot_content_pin(id: Hash, hash: Hash) -> String {
45    format!("{SNAPSHOT_PIN_PREFIX}{id}/blob/{hash}")
46}
47
48/// Pin name for a one-off downloaded blob.
49#[must_use]
50pub fn download_pin(hash: Hash) -> String {
51    format!("{DOWNLOAD_PIN_PREFIX}{hash}")
52}