[WIP] A (somewhat barebones) atproto app for creating custom sites without hosting!

upload: upload blobs and store reference to remote cid

note: this doesnt work bc the auth is failing BUT once i fix auth it will

vielle.dev f58a29eb 651208c9

verified
Changed files
+34 -3
upload
+32 -2
upload/src/main.rs
··· 3 3 use jacquard::{ 4 4 Data, 5 5 api::com_atproto::{self, repo::list_records::ListRecords}, 6 - client::{Agent, credential_session::CredentialSession}, 6 + client::{Agent, AgentSessionExt, credential_session::CredentialSession}, 7 7 cowstr::ToCowStr, 8 8 identity::JacquardResolver, 9 9 types::{ident::AtIdentifier, nsid::Nsid, string::AtprotoStr, uri::Uri}, 10 10 xrpc::XrpcExt, 11 11 }; 12 - use std::path::PathBuf; 12 + use std::{collections::HashMap, fs, path::PathBuf}; 13 + 14 + use crate::sitemap::{BlobRef, Sitemap, SitemapNode}; 13 15 14 16 mod sitemap; 15 17 mod utils; ··· 136 138 println!("{remote_records:?}"); 137 139 138 140 // upload local site blobs 141 + let mut new_sitemap: Sitemap = HashMap::new(); 142 + for (k, v) in local_sitemap { 143 + let blob = match v.blob { 144 + BlobRef::Local(path) => path, 145 + BlobRef::Remote(_) => { 146 + panic!("Impossible state") 147 + } 148 + }; 149 + let blob = fs::read(blob).or_else(|err| { 150 + println!("FS error: {err}"); 151 + Err(()) 152 + })?; 153 + let res = agent 154 + .upload_blob(blob, v.mime_type.clone().into()) 155 + .await 156 + .or_else(|err| { 157 + println!("Blob upload error: {err}"); 158 + Err(()) 159 + })?; 160 + new_sitemap.insert( 161 + k, 162 + SitemapNode { 163 + mime_type: v.mime_type, 164 + blob: BlobRef::Remote(res.r#ref), 165 + }, 166 + ); 167 + } 168 + println!("{:#?}", new_sitemap); 139 169 140 170 // batch delete/upload records 141 171
+2 -1
upload/src/sitemap.rs
··· 1 1 use ignore::WalkBuilder; 2 + use jacquard::types::cid::Cid; 2 3 use mime_guess::mime; 3 4 use std::{collections::HashMap, error::Error, fmt, path::PathBuf}; 4 5 ··· 13 14 #[derive(Debug)] 14 15 pub enum BlobRef { 15 16 Local(PathBuf), 16 - Remote(String), 17 + Remote(Cid<'static>), 17 18 } 18 19 19 20 #[derive(Debug)]