Monorepo for wisp.place. A static site hosting service built on top of the AT Protocol.
wisp.place
1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3use std::path::Path;
4use miette::IntoDiagnostic;
5
6/// Metadata tracking file CIDs for incremental updates
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct SiteMetadata {
9 /// Record CID from the PDS
10 pub record_cid: String,
11 /// Map of file paths to their blob CIDs
12 pub file_cids: HashMap<String, String>,
13 /// Timestamp when the site was last synced
14 pub last_sync: i64,
15}
16
17impl SiteMetadata {
18 pub fn new(record_cid: String, file_cids: HashMap<String, String>) -> Self {
19 Self {
20 record_cid,
21 file_cids,
22 last_sync: chrono::Utc::now().timestamp(),
23 }
24 }
25
26 /// Load metadata from a directory
27 pub fn load(dir: &Path) -> miette::Result<Option<Self>> {
28 let metadata_path = dir.join(".wisp-metadata.json");
29 if !metadata_path.exists() {
30 return Ok(None);
31 }
32
33 let contents = std::fs::read_to_string(&metadata_path).into_diagnostic()?;
34 let metadata: SiteMetadata = serde_json::from_str(&contents).into_diagnostic()?;
35 Ok(Some(metadata))
36 }
37
38 /// Save metadata to a directory
39 pub fn save(&self, dir: &Path) -> miette::Result<()> {
40 let metadata_path = dir.join(".wisp-metadata.json");
41 let contents = serde_json::to_string_pretty(self).into_diagnostic()?;
42 std::fs::write(&metadata_path, contents).into_diagnostic()?;
43 Ok(())
44 }
45}
46