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, SNAPSHOT_PIN_PREFIX,
15};
16
17/// Pin name for a publicly shared folder blob.
18#[must_use]
19pub fn public_blob_pin(namespace_id: NamespaceId, hash: Hash) -> String {
20    format!("{PUBLIC_PIN_PREFIX}{namespace_id}/{hash}")
21}
22
23/// Pin name for a published collection manifest blob.
24#[must_use]
25pub fn collection_manifest_pin(hash: Hash) -> String {
26    format!("{COLLECTION_MANIFEST_PIN_PREFIX}{hash}")
27}
28
29/// Pin name for a content blob referenced by a published collection.
30#[must_use]
31pub fn collection_content_pin(collection_id: Uuid, hash: Hash) -> String {
32    format!("{COLLECTION_PIN_PREFIX}{collection_id}/{hash}")
33}
34
35/// Pin name for a snapshot manifest blob.
36#[must_use]
37pub fn snapshot_manifest_pin(id: Hash) -> String {
38    format!("{SNAPSHOT_PIN_PREFIX}{id}/manifest")
39}
40
41/// Pin name for a content blob referenced by a snapshot.
42#[must_use]
43pub fn snapshot_content_pin(id: Hash, hash: Hash) -> String {
44    format!("{SNAPSHOT_PIN_PREFIX}{id}/blob/{hash}")
45}
46
47/// Pin name for a one-off downloaded blob.
48#[must_use]
49pub fn download_pin(hash: Hash) -> String {
50    format!("{DOWNLOAD_PIN_PREFIX}{hash}")
51}