diff options
author | bryan newbold <bnewbold@robocracy.org> | 2023-08-20 19:56:22 -0700 |
---|---|---|
committer | bryan newbold <bnewbold@robocracy.org> | 2023-08-20 19:56:22 -0700 |
commit | 23416af782a179a658711e958e977e19ae97067b (patch) | |
tree | 09e605dbd105c0628f6614e421c0dd43bb8ce3dc /adenosine-pds/src/lib.rs | |
parent | cc1dea6ea34260201c1df09959c7c4566d16d918 (diff) | |
download | adenosine-23416af782a179a658711e958e977e19ae97067b.tar.gz adenosine-23416af782a179a658711e958e977e19ae97067b.zip |
many updates from spring 2023 lex refactor
Diffstat (limited to 'adenosine-pds/src/lib.rs')
-rw-r--r-- | adenosine-pds/src/lib.rs | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/adenosine-pds/src/lib.rs b/adenosine-pds/src/lib.rs index c267135..cb41cb9 100644 --- a/adenosine-pds/src/lib.rs +++ b/adenosine-pds/src/lib.rs @@ -303,7 +303,7 @@ fn xrpc_get_handler( ) } "com.atproto.repo.getRecord" => { - let did = Did::from_str(&xrpc_required_param(request, "user")?)?; + let did = Did::from_str(&xrpc_required_param(request, "repo")?)?; let collection = Nsid::from_str(&xrpc_required_param(request, "collection")?)?; let rkey = Tid::from_str(&xrpc_required_param(request, "rkey")?)?; let mut srv = srv.lock().or(Err(XrpcError::MutexPoisoned))?; @@ -317,8 +317,8 @@ fn xrpc_get_handler( Err(e) => Err(e), } } - "com.atproto.sync.getRoot" => { - let did = Did::from_str(&xrpc_required_param(request, "did")?)?; + "com.atproto.sync.getHead" => { + let did = Did::from_str(&xrpc_required_param(request, "repo")?)?; let mut srv = srv.lock().or(Err(XrpcError::MutexPoisoned))?; srv.repo .lookup_commit(&did)? @@ -329,7 +329,7 @@ fn xrpc_get_handler( // TODO: limit, before, after, tid, reverse // TODO: handle non-DID 'user' // TODO: limit result set size - let did = Did::from_str(&xrpc_required_param(request, "user")?)?; + let did = Did::from_str(&xrpc_required_param(request, "repo")?)?; let collection = Nsid::from_str(&xrpc_required_param(request, "collection")?)?; let mut record_list: Vec<Value> = vec![]; let mut srv = srv.lock().or(Err(XrpcError::MutexPoisoned))?; @@ -350,15 +350,6 @@ fn xrpc_get_handler( } Ok(json!({ "records": record_list })) } - "com.atproto.session.get" => { - let mut srv = srv.lock().or(Err(XrpcError::MutexPoisoned))?; - let auth_did = &xrpc_check_auth_header(&mut srv, request, None)?; - let handle = srv - .atp_db - .resolve_did(auth_did)? - .expect("registered account has handle"); - Ok(json!({"did": auth_did.to_string(), "handle": handle})) - } "com.atproto.handle.resolve" => { let handle = xrpc_required_param(request, "handle")?; let mut srv = srv.lock().or(Err(XrpcError::MutexPoisoned))?; @@ -370,17 +361,17 @@ fn xrpc_get_handler( } } "com.atproto.repo.describe" => { - let did = Did::from_str(&xrpc_required_param(request, "user")?)?; + let did = Did::from_str(&xrpc_required_param(request, "repo")?)?; let mut srv = srv.lock().or(Err(XrpcError::MutexPoisoned))?; let did_doc = srv.atp_db.get_did_doc(&did)?; let collections: Vec<String> = srv.repo.collections(&did)?; let desc = com_atproto::repo::Describe { - name: did.to_string(), // TODO: handle? + handle: did.to_string(), // TODO: handle? did: did.to_string(), didDoc: did_doc, collections, - nameIsCorrect: true, + handleIsCorrect: true, }; Ok(json!(desc)) } @@ -408,7 +399,7 @@ fn xrpc_get_handler( } "app.bsky.feed.getAuthorFeed" => { // TODO did or handle - let did = Did::from_str(&xrpc_required_param(request, "author")?)?; + let did = Did::from_str(&xrpc_required_param(request, "actor")?)?; let mut srv = srv.lock().unwrap(); Ok(json!(bsky_get_author_feed(&mut srv, &did)?)) } @@ -434,7 +425,7 @@ fn xrpc_get_handler( let _auth_did = &xrpc_check_auth_header(&mut srv, request, None)?; Ok(json!({"count": 0})) } - "app.bsky.notification.list" => { + "app.bsky.notification.listNotifications" => { // TODO: actual implementation let mut srv = srv.lock().or(Err(XrpcError::MutexPoisoned))?; let _auth_did = &xrpc_check_auth_header(&mut srv, request, None)?; @@ -447,7 +438,7 @@ fn xrpc_get_handler( } fn xrpc_get_repo_handler(srv: &Mutex<AtpService>, request: &Request) -> Result<Vec<u8>> { - let did = Did::from_str(&xrpc_required_param(request, "did")?)?; + let did = Did::from_str(&xrpc_required_param(request, "repo")?)?; let mut srv = srv.lock().or(Err(XrpcError::MutexPoisoned))?; // TODO: don't unwrap here let commit_cid = srv.repo.lookup_commit(&did)?.unwrap(); @@ -520,7 +511,7 @@ fn xrpc_post_handler( request: &Request, ) -> Result<serde_json::Value> { match method { - "com.atproto.account.create" => { + "com.atproto.server.createAccount" => { // validate account request let req: com_atproto::AccountRequest = rouille::input::json_input(request) .map_err(|e| XrpcError::BadRequest(format!("failed to parse JSON body: {e}")))?; @@ -546,18 +537,18 @@ fn xrpc_post_handler( let sess = create_account(&mut srv, &req, true)?; Ok(json!(sess)) } - "com.atproto.session.create" => { + "com.atproto.server.createSession" => { let req: com_atproto::SessionRequest = rouille::input::json_input(request) .map_err(|e| XrpcError::BadRequest(format!("failed to parse JSON body: {e}")))?; let mut srv = srv.lock().unwrap(); let keypair = srv.pds_keypair.clone(); Ok(json!(srv.atp_db.create_session( - &req.handle, + &req.identifier, &req.password, &keypair )?)) } - "com.atproto.session.refresh" => { + "com.atproto.server.refreshSession" => { // actually just returns current session, because we don't implement refresh let mut srv = srv.lock().unwrap(); let did = xrpc_check_auth_header(&mut srv, request, None)?; @@ -576,11 +567,12 @@ fn xrpc_post_handler( Ok(json!(com_atproto::Session { did: did.to_string(), name: handle, + email: None, accessJwt: jwt.to_string(), refreshJwt: jwt.to_string(), })) } - "com.atproto.session.delete" => { + "com.atproto.server.deleteSession" => { let mut srv = srv.lock().unwrap(); let _did = xrpc_check_auth_header(&mut srv, request, None)?; let header = request @@ -597,10 +589,10 @@ fn xrpc_post_handler( }; Ok(json!({})) } - "com.atproto.repo.batchWrite" => { + "com.atproto.repo.applyWrites" => { let batch: com_atproto::repo::BatchWriteBody = rouille::input::json_input(request)?; // TODO: validate edits against schemas - let did = Did::from_str(&batch.did)?; + let did = Did::from_str(&batch.repo)?; let mut srv = srv.lock().unwrap(); let _auth_did = &xrpc_check_auth_header(&mut srv, request, Some(&did))?; let mut mutations: Vec<Mutation> = Default::default(); @@ -613,12 +605,12 @@ fn xrpc_post_handler( .as_ref() .map(|t| Tid::from_str(t).unwrap()) .unwrap_or_else(|| srv.tid_gen.next_tid()), - json_value_into_ipld(w.value.clone()), + json_value_into_ipld(w.value.clone().unwrap()), ), "update" => Mutation::Update( Nsid::from_str(&w.collection)?, Tid::from_str(w.rkey.as_ref().unwrap())?, - json_value_into_ipld(w.value.clone()), + json_value_into_ipld(w.value.clone().unwrap()), ), "delete" => Mutation::Delete( Nsid::from_str(&w.collection)?, @@ -685,7 +677,7 @@ fn xrpc_post_handler( } "com.atproto.sync.updateRepo" => { // TODO: all other XRPC POST methods removed params (eg, 'did' in this case) - let did = Did::from_str(&xrpc_required_param(request, "did")?)?; + let did = Did::from_str(&xrpc_required_param(request, "repo")?)?; // important that this read is before we take the mutex, because it could be slow! let mut car_bytes: Vec<u8> = Default::default(); // TODO: unwrap() @@ -769,7 +761,7 @@ fn account_view_handler( Ok(AccountView { domain: host.to_string(), did: did.clone(), - profile: bsky_get_profile(&mut srv, &did)?, + profile: bsky_get_profile_detailed(&mut srv, &did)?, feed: bsky_get_author_feed(&mut srv, &did)?.feed, } .render()?) @@ -809,11 +801,11 @@ fn repo_view_handler(srv: &Mutex<AtpService>, did: &str, request: &Request) -> R let commit = srv.repo.get_commit(commit_cid)?; let collections: Vec<String> = srv.repo.collections(&did)?; let desc = com_atproto::repo::Describe { - name: did.to_string(), // TODO + handle: did.to_string(), // TODO did: did.to_string(), didDoc: did_doc, collections, - nameIsCorrect: true, + handleIsCorrect: true, }; Ok(RepoView { |