Atproto, Router, add atproto api mod with Nsid
Sets up a generic atproto module to store atproto implementation. Mainly doing this so that I can switch between rsky/atrium as well as add my own layers on top. This also switches the old Xrpc/Router use of Nsid to the atproto api implementation of it. Next up is the DB where I'll need a bunch of these.
This commit is contained in:
parent
d4a3a71e2f
commit
db33099405
6 changed files with 858 additions and 32 deletions
|
|
@ -1,3 +1,4 @@
|
|||
use crate::atproto::Nsid;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
pin::Pin,
|
||||
|
|
@ -26,13 +27,13 @@ use axum::{
|
|||
};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
enum Nsid {
|
||||
Nsid(String),
|
||||
enum Path {
|
||||
Nsid(Nsid),
|
||||
NotImplemented,
|
||||
}
|
||||
|
||||
pub struct XrpcEndpoint {
|
||||
nsid: Nsid,
|
||||
path: Path,
|
||||
resolver: MethodRouter,
|
||||
}
|
||||
|
||||
|
|
@ -123,12 +124,12 @@ where
|
|||
}
|
||||
|
||||
impl XrpcEndpoint {
|
||||
pub fn new_query<Q>(nsid: String, query: Q) -> Self
|
||||
pub fn new_query<Q>(nsid: Nsid, query: Q) -> Self
|
||||
where
|
||||
Q: XrpcHandler<QueryInput> + Clone
|
||||
{
|
||||
XrpcEndpoint {
|
||||
nsid: Nsid::Nsid(nsid),
|
||||
path: Path::Nsid(nsid),
|
||||
resolver: get(async move | mut parts: Parts | -> Response {
|
||||
match QueryInput::from_request_parts(&mut parts, &()).await {
|
||||
Ok(qi) => query.call(qi).await,
|
||||
|
|
@ -138,12 +139,12 @@ impl XrpcEndpoint {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new_procedure<P>(nsid: String, procedure: P) -> Self
|
||||
pub fn new_procedure<P>(nsid: Nsid, procedure: P) -> Self
|
||||
where
|
||||
P: XrpcHandler<ProcedureInput> + Clone
|
||||
{
|
||||
XrpcEndpoint {
|
||||
nsid: Nsid::Nsid(nsid),
|
||||
path: Path::Nsid(nsid),
|
||||
resolver: post(async move | req: Request | -> Response {
|
||||
match ProcedureInput::from_request(req, &()).await {
|
||||
Ok(pi) => procedure.call(pi).await,
|
||||
|
|
@ -154,9 +155,9 @@ impl XrpcEndpoint {
|
|||
}
|
||||
|
||||
pub fn add_to_router(self, router: axumRouter) -> axumRouter {
|
||||
let path = match self.nsid {
|
||||
Nsid::Nsid(s) => &("/xrpc/".to_owned() + &s),
|
||||
Nsid::NotImplemented => "/xrpc/{*nsid}",
|
||||
let path = match self.path {
|
||||
Path::Nsid(nsid) => &("/xrpc/".to_owned() + nsid.as_str()),
|
||||
Path::NotImplemented => "/xrpc/{*nsid}",
|
||||
};
|
||||
|
||||
router.route(path, self.resolver)
|
||||
|
|
@ -172,7 +173,7 @@ impl XrpcEndpoint {
|
|||
);
|
||||
|
||||
XrpcEndpoint {
|
||||
nsid: Nsid::NotImplemented,
|
||||
path: Path::NotImplemented,
|
||||
resolver: get(resolver.clone()).post(resolver),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue