Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm

identities!!!!

+25 -11
+25 -11
slingshot/src/server.rs
··· 55 55 "zQ3shpq1g134o7HGDb86CtQFxnHqzx5pZWknrVX2Waum3fF6j".to_string() 56 56 } 57 57 58 - #[derive(Object)] 58 + #[derive(Debug, Object)] 59 59 #[oai(example = true)] 60 60 struct XrpcErrorResponseObject { 61 61 /// Should correspond an error `name` in the lexicon errors array ··· 215 215 216 216 #[derive(Object)] 217 217 struct ProxyHydrationIdentifierFound { 218 - record: MiniDocResponseObject, 218 + mini_doc: MiniDocResponseObject, 219 219 } 220 220 221 221 // todo: there's gotta be a supertrait that collects these? ··· 597 597 #[oai(example = "example_handle")] 598 598 Query(identifier): Query<String>, 599 599 ) -> ResolveMiniIDResponse { 600 + Self::resolve_mini_doc_impl(&identifier, self.identity.clone()).await 601 + } 602 + 603 + async fn resolve_mini_doc_impl(identifier: &str, identity: Identity) -> ResolveMiniIDResponse { 600 604 let invalid = |reason: &'static str| { 601 605 ResolveMiniIDResponse::BadRequest(xrpc_error("InvalidRequest", reason)) 602 606 }; 603 607 604 608 let mut unverified_handle = None; 605 - let did = match Did::new(identifier.clone()) { 609 + let did = match Did::new(identifier.to_string()) { 606 610 Ok(did) => did, 607 611 Err(_) => { 608 612 let Ok(alleged_handle) = Handle::new(identifier.to_lowercase()) else { 609 613 return invalid("Identifier was not a valid DID or handle"); 610 614 }; 611 615 612 - match self.identity.handle_to_did(alleged_handle.clone()).await { 616 + match identity.handle_to_did(alleged_handle.clone()).await { 613 617 Ok(res) => { 614 618 if let Some(did) = res { 615 619 // we did it joe ··· 627 631 } 628 632 } 629 633 }; 630 - let Ok(partial_doc) = self.identity.did_to_partial_mini_doc(&did).await else { 634 + let Ok(partial_doc) = identity.did_to_partial_mini_doc(&did).await else { 631 635 return invalid("Failed to get DID doc"); 632 636 }; 633 637 let Some(partial_doc) = partial_doc else { ··· 647 651 "handle.invalid".to_string() 648 652 } 649 653 } else { 650 - let Ok(handle_did) = self 651 - .identity 654 + let Ok(handle_did) = identity 652 655 .handle_to_did(partial_doc.unverified_handle.clone()) 653 656 .await 654 657 else { ··· 782 785 } 783 786 let mut u = url::Url::parse("https://example.com").unwrap(); 784 787 u.query_pairs_mut().append_pair("identifier", &id); 785 - identifiers.insert(id, Hydration::Pending(ProxyHydrationPending { 788 + identifiers.insert(id.clone(), Hydration::Pending(ProxyHydrationPending { 786 789 url: format!("/xrpc/blue.microcosm.identity.resolveMiniDoc?{}", u.query().unwrap()), // gross 787 790 })); 788 791 let tx = tx.clone(); 789 - // let doc_fut = self.resolve_mini_doc(); 790 - tokio::task::spawn(async { 791 - 792 + let identity = self.identity.clone(); 793 + tokio::task::spawn(async move { 794 + let res = match Self::resolve_mini_doc_impl(&id, identity).await { 795 + ResolveMiniIDResponse::Ok(Json(mini_doc)) => Hydration::Found(ProxyHydrationIdentifierFound { 796 + mini_doc 797 + }), 798 + ResolveMiniIDResponse::BadRequest(e) => { 799 + log::warn!("minidoc fail: {:?}", e.0); 800 + Hydration::Error(ProxyHydrationError { 801 + reason: "failed to resolve mini doc".to_string(), 802 + }) 803 + } 804 + }; 805 + tx.send(GetThing::Identifier(id, res)).await 792 806 }); 793 807 } 794 808 }