lightweight com.atproto.sync.listReposByCollection
45
fork

Configure Feed

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

query override: derive version (booo)

phil c27e243f 20eafce2

+48 -5
+11 -3
src/server/list_repos_by_collection.rs
··· 10 10 response::{IntoResponse, Response}, 11 11 }; 12 12 use jacquard_api::com_atproto::sync::list_repos_by_collection::{ 13 - ListReposByCollectionOutput, ListReposByCollectionRequest, Repo, 13 + ListReposByCollectionOutput, Repo, 14 14 }; 15 15 use jacquard_axum::ExtractXrpc; 16 16 use jacquard_common::IntoStatic; 17 17 use jacquard_common::types::string::Did; 18 + 19 + use super::list_repos_by_collection_params::ListReposByCollectionEndpoint; 18 20 use serde_json::json; 19 21 20 22 use crate::storage::{DbRef, error::StorageError}; ··· 66 68 /// the lexicon, because bluesky's own collectiondir only clamps at 10k. 67 69 pub async fn list_repos_by_collection( 68 70 State(db): State<DbRef>, 69 - ExtractXrpc(req): ExtractXrpc<ListReposByCollectionRequest>, 71 + ExtractXrpc(req): ExtractXrpc<ListReposByCollectionEndpoint>, 70 72 ) -> Result<Json<ListReposByCollectionOutput<'static>>, ListReposByCollectionError> { 71 73 let limit = req.limit.unwrap_or(500).clamp(1, 10_000) as usize; 72 74 ··· 77 79 .transpose() 78 80 .map_err(|_| ListReposByCollectionError::BadCursor)?; 79 81 80 - let collection = req.collection.into_static(); 82 + // TODO: multi-collection support. For now require exactly one collection. 83 + let collection = req 84 + .collection 85 + .into_iter() 86 + .next() 87 + .ok_or(ListReposByCollectionError::BadCursor)? 88 + .into_static(); 81 89 let (dids, next) = tokio::task::spawn_blocking({ 82 90 let db = db.clone(); 83 91 move || {
+34
src/server/list_repos_by_collection_params.rs
··· 1 + //! Temporary override of `com.atproto.sync.listReposByCollection` request types. 2 + //! 3 + //! The updated lexicon accepts `collection` as an optional array of NSIDs rather 4 + //! than a single required NSID. Remove this file and revert the changes in 5 + //! `mod.rs` and `list_repos_by_collection.rs` once the upstream `jacquard-api` 6 + //! crate is updated to match. 7 + 8 + use jacquard_api::com_atproto::sync::list_repos_by_collection::ListReposByCollectionOutput; 9 + use jacquard_common::CowStr; 10 + use jacquard_common::types::string::Nsid; 11 + 12 + #[derive( 13 + serde::Serialize, 14 + serde::Deserialize, 15 + Debug, 16 + Clone, 17 + jacquard_derive::IntoStatic, 18 + jacquard_derive::XrpcRequest, 19 + )] 20 + #[serde(rename_all = "camelCase")] 21 + #[xrpc( 22 + nsid = "com.atproto.sync.listReposByCollection", 23 + method = Query, 24 + output = ListReposByCollectionOutput, 25 + server, 26 + )] 27 + pub struct ListReposByCollection<'a> { 28 + #[serde(default, borrow)] 29 + pub collection: Vec<Nsid<'a>>, 30 + #[serde(skip_serializing_if = "Option::is_none", borrow)] 31 + pub cursor: Option<CowStr<'a>>, 32 + #[serde(skip_serializing_if = "Option::is_none")] 33 + pub limit: Option<i64>, 34 + }
+3 -2
src/server/mod.rs
··· 7 7 mod hello; 8 8 mod list_repos; 9 9 mod list_repos_by_collection; 10 + mod list_repos_by_collection_params; 10 11 11 12 use get_repo_status::get_repo_status; 12 13 use list_repos::list_repos; ··· 16 17 17 18 use jacquard_api::com_atproto::sync::{ 18 19 get_repo_status::GetRepoStatusRequest, list_repos::ListReposRequest, 19 - list_repos_by_collection::ListReposByCollectionRequest, 20 20 }; 21 21 use jacquard_axum::IntoRouter; 22 + use list_repos_by_collection_params::ListReposByCollectionEndpoint; 22 23 23 24 use crate::error::Result; 24 25 use crate::storage::DbRef; ··· 36 37 ) -> Result<()> { 37 38 let app = GetRepoStatusRequest::into_router(get_repo_status) 38 39 .merge(ListReposRequest::into_router(list_repos)) 39 - .merge(ListReposByCollectionRequest::into_router( 40 + .merge(ListReposByCollectionEndpoint::into_router( 40 41 list_repos_by_collection, 41 42 )) 42 43 .with_state(db)