grain.social is a photo sharing platform built on atproto.
1use crate::types::GalleryResponse;
2use anyhow::{anyhow, Result};
3use reqwest;
4use tracing::info;
5
6pub async fn fetch_gallery_data(gallery_uri: &str) -> Result<GalleryResponse> {
7 let base_url = std::env::var("GRAIN_BASE_URL").unwrap_or_else(|_| "https://grain.social".to_string());
8 let gallery_url = format!(
9 "{}/xrpc/social.grain.gallery.getGallery?uri={}",
10 base_url,
11 urlencoding::encode(gallery_uri)
12 );
13
14 info!("Fetching gallery data from: {}", gallery_url);
15
16 let response = reqwest::get(&gallery_url).await?;
17
18 if !response.status().is_success() {
19 return Err(anyhow!("Failed to fetch gallery: {}", response.status()));
20 }
21
22 let data: GalleryResponse = response.json().await?;
23
24 if data.items.is_empty() {
25 return Err(anyhow!("No items found in gallery"));
26 }
27
28 Ok(data)
29}
30