lightweight com.atproto.sync.listReposByCollection
45
fork

Configure Feed

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

mostly impl getrepostatus

phil c4b7593b 7aa8bf46

+30 -9
+30 -9
src/server/handler.rs
··· 9 9 list_repos_by_collection::{ListReposByCollectionOutput, ListReposByCollectionRequest, Repo}, 10 10 }; 11 11 use jacquard_axum::ExtractXrpc; 12 - use jacquard_common::types::string::Did; 12 + use jacquard_common::{CowStr, types::string::Did}; 13 13 14 - use crate::storage::DbRef; 14 + use crate::storage::{DbRef, repo::AccountStatus}; 15 15 16 16 /// Handler for `GET /xrpc/com.atproto.sync.listReposByCollection`. 17 17 /// ··· 66 66 67 67 /// Handler for `GET /xrpc/com.atproto.sync.getRepoStatus`. 68 68 /// 69 - /// Looks up the per-repo state from `db::repo::get` and returns whether the 70 - /// repo is active. Returns a `RepoNotFound` XRPC error (404) if the DID has 71 - /// never been indexed. 69 + /// Returns the active/status of the given repo. Returns 404 (XRPC RepoNotFound) 70 + /// if the DID has never been indexed. 71 + /// 72 + /// `active` reflects whether the account is usable. `status` carries the 73 + /// reason when inactive ("takendown", "suspended", "deactivated", "deleted"). 74 + /// `rev` is currently omitted (TODO: store latest rev in RepoRecord). 75 + /// 76 + /// TODO: 400 xrpc-compatible error instead of 404 77 + /// jacquard-axum seems slightly limiting here atm 72 78 pub async fn get_repo_status( 73 - State(_db): State<DbRef>, 74 - ExtractXrpc(_req): ExtractXrpc<GetRepoStatusRequest>, 79 + State(db): State<DbRef>, 80 + ExtractXrpc(req): ExtractXrpc<GetRepoStatusRequest>, 75 81 ) -> Result<Json<GetRepoStatusOutput<'static>>, StatusCode> { 76 - // req.did — Did<'static> 77 - todo!("look up RepoRecord in db and return active/status") 82 + let record = crate::storage::repo::get(&db, &req.did) 83 + .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)? 84 + .ok_or(StatusCode::NOT_FOUND)?; 85 + 86 + let active = matches!(record.status, AccountStatus::Active); 87 + let status: Option<CowStr<'static>> = match record.status { 88 + AccountStatus::Active => None, 89 + s => Some(s.as_str().to_owned().into()), 90 + }; 91 + 92 + Ok(Json(GetRepoStatusOutput { 93 + active, 94 + did: req.did, 95 + rev: None, // TODO: store and return the latest rev from RepoRecord 96 + status, 97 + extra_data: None, 98 + })) 78 99 }