This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

at main 1.2 kB View raw
1use atrium_api::types::{Blob, CidLink}; 2use anyhow::{Result, anyhow}; 3use reqwest::Client; 4use tracing::{info, debug}; 5use bytes::Bytes; 6use std::str::FromStr; 7 8pub async fn fetch_blob(did: &str, cid: &str, endpoint: &str) -> Result<Bytes> { 9 let url = format!("{}/xrpc/com.atproto.sync.getBlob?did={}&cid={}", endpoint.trim_end_matches('/'), did, cid); 10 let client = Client::new(); 11 let response = client.get(&url).timeout(std::time::Duration::from_secs(5)).send().await?; 12 response.error_for_status_ref()?; 13 let content = response.bytes().await?; 14 info!("Fetched blob {} successfully.", cid); 15 Ok(content) 16} 17 18pub async fn get_blob_metadata(cid: &str, did: &str, endpoint: &str) -> Result<Blob> { 19 info!("Retrieving metadata for blob {}.", cid); 20 let blob_data = fetch_blob(did, cid, endpoint).await?; 21 22 let kind = infer::get(&blob_data).ok_or_else(|| anyhow!("Could not infer mime type for blob {}", cid))?; 23 let mime_type = kind.mime_type().to_string(); 24 let size = blob_data.len(); 25 26 debug!("Blob metadata: MIME Type - {}, Size - {}", mime_type, size); 27 28 Ok(Blob { 29 r#ref: CidLink(cid::Cid::from_str(cid).map_err(|e| anyhow!("{:?}", e))?), 30 mime_type, 31 size, 32 }) 33}