-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_blobs.rs
More file actions
111 lines (98 loc) · 2.94 KB
/
Copy pathlist_blobs.rs
File metadata and controls
111 lines (98 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//! com.atproto.sync.listBlobs endpoint.
//!
//! Lists blob CIDs for a repository with pagination.
use std::net::SocketAddr;
use std::sync::Arc;
use axum::{
Json,
extract::{ConnectInfo, Query, State},
http::{HeaderMap, StatusCode},
response::{IntoResponse, Response},
};
use serde::{Deserialize, Serialize};
use crate::pds::db::StatisticKey;
use crate::pds::server::PdsState;
use super::{get_caller_info};
/// Query parameters for listBlobs.
#[derive(Deserialize)]
pub struct ListBlobsQuery {
/// Repository DID (optional, defaults to local user).
#[allow(dead_code)]
did: Option<String>,
/// Maximum number of blobs to return (default: 100).
limit: Option<i32>,
/// Cursor for pagination.
cursor: Option<String>,
}
/// Successful response for listBlobs.
#[derive(Serialize)]
pub struct ListBlobsResponse {
/// List of blob CIDs.
cids: Vec<String>,
/// Cursor for the next page.
#[serde(skip_serializing_if = "Option::is_none")]
cursor: Option<String>,
}
/// Error response for listBlobs.
#[derive(Serialize)]
pub struct ListBlobsError {
error: String,
message: String,
}
/// GET /xrpc/com.atproto.sync.listBlobs - List blob CIDs.
///
/// Returns a paginated list of blob CIDs stored in the repository.
///
/// # Query Parameters
///
/// * `did` - Optional repository DID (defaults to local user)
/// * `limit` - Maximum blobs to return (default: 100)
/// * `cursor` - Pagination cursor
///
/// # Returns
///
/// * `200 OK` with list of blob CIDs
pub async fn list_blobs(
State(state): State<Arc<PdsState>>,
ConnectInfo(addr): ConnectInfo<SocketAddr>,
headers: HeaderMap,
Query(query): Query<ListBlobsQuery>,
) -> Response {
// Get caller info for statistics
let (ip_address, user_agent) = get_caller_info(&headers, Some(addr));
// Increment statistics
let stat_key = StatisticKey {
name: "xrpc/com.atproto.sync.listBlobs".to_string(),
ip_address,
user_agent,
};
let _ = state.db.increment_statistic_for_endpoint(&stat_key);
// Parse limit with default of 100
let limit = query.limit.unwrap_or(100).min(1000).max(1);
// Get blob list with pagination
let blobs = match state.db.list_blobs_with_cursor(query.cursor.as_deref(), limit) {
Ok(b) => b,
Err(e) => {
return (
StatusCode::INTERNAL_SERVER_ERROR,
Json(ListBlobsError {
error: "InternalError".to_string(),
message: format!("Failed to list blobs: {}", e),
}),
)
.into_response();
}
};
// Determine next cursor (last CID if we have results)
let next_cursor = if !blobs.is_empty() {
Some(blobs[blobs.len() - 1].clone())
} else {
None
};
// Return response
let response = ListBlobsResponse {
cids: blobs,
cursor: next_cursor,
};
(StatusCode::OK, Json(response)).into_response()
}