From a0d99343e164516a5d6dfe814170178580adad3f Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 19 Dec 2022 19:57:46 -0800 Subject: pds: XRPC POST params moved from query to body --- adenosine-pds/src/lib.rs | 28 +++++++++++++++------------- adenosine-pds/src/models.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/adenosine-pds/src/lib.rs b/adenosine-pds/src/lib.rs index 8e32692..d40058e 100644 --- a/adenosine-pds/src/lib.rs +++ b/adenosine-pds/src/lib.rs @@ -619,7 +619,7 @@ fn xrpc_post_handler( "com.atproto.repo.batchWrite" => { let batch: RepoBatchWriteBody = rouille::input::json_input(request)?; // TODO: validate edits against schemas - let did = Did::from_str(&xrpc_required_param(request, "did")?)?; + let did = Did::from_str(&batch.did)?; let mut srv = srv.lock().unwrap(); let _auth_did = &xrpc_check_auth_header(&mut srv, request, Some(&did))?; let mut mutations: Vec = Default::default(); @@ -654,15 +654,15 @@ fn xrpc_post_handler( } "com.atproto.repo.createRecord" => { // TODO: validate edits against schemas - let did = Did::from_str(&xrpc_required_param(request, "did")?)?; - let collection = Nsid::from_str(&xrpc_required_param(request, "collection")?)?; - let record: Value = rouille::input::json_input(request)?; + let create: RepoCreateRecord = rouille::input::json_input(request)?; + let did = Did::from_str(&create.did)?; + let collection = Nsid::from_str(&create.collection)?; let mut srv = srv.lock().unwrap(); let _auth_did = &xrpc_check_auth_header(&mut srv, request, Some(&did))?; let mutations: Vec = vec![Mutation::Create( collection, srv.tid_gen.next_tid(), - json_value_into_ipld(record), + json_value_into_ipld(create.record), )]; let keypair = srv.pds_keypair.clone(); srv.repo.mutate_repo(&did, &mutations, &keypair)?; @@ -671,17 +671,17 @@ fn xrpc_post_handler( } "com.atproto.repo.putRecord" => { // TODO: validate edits against schemas - let did = Did::from_str(&xrpc_required_param(request, "did")?)?; - let collection = Nsid::from_str(&xrpc_required_param(request, "collection")?)?; - let tid = Tid::from_str(&xrpc_required_param(request, "rkey")?)?; - let record: Value = rouille::input::json_input(request)?; + let put: RepoPutRecord = rouille::input::json_input(request)?; + let did = Did::from_str(&put.did)?; + let collection = Nsid::from_str(&put.collection)?; + let tid = Tid::from_str(&put.rkey)?; let mut srv = srv.lock().unwrap(); let _auth_did = &xrpc_check_auth_header(&mut srv, request, Some(&did))?; let mutations: Vec = vec![Mutation::Update( collection, tid, - json_value_into_ipld(record), + json_value_into_ipld(put.record), )]; let keypair = srv.pds_keypair.clone(); srv.repo.mutate_repo(&did, &mutations, &keypair)?; @@ -689,9 +689,10 @@ fn xrpc_post_handler( Ok(json!({})) } "com.atproto.repo.deleteRecord" => { - let did = Did::from_str(&xrpc_required_param(request, "did")?)?; - let collection = Nsid::from_str(&xrpc_required_param(request, "collection")?)?; - let tid = Tid::from_str(&xrpc_required_param(request, "rkey")?)?; + let delete: RepoDeleteRecord = rouille::input::json_input(request)?; + let did = Did::from_str(&delete.did)?; + let collection = Nsid::from_str(&delete.collection)?; + let tid = Tid::from_str(&delete.rkey)?; let mut srv = srv.lock().unwrap(); let _auth_did = &xrpc_check_auth_header(&mut srv, request, Some(&did))?; @@ -702,6 +703,7 @@ fn xrpc_post_handler( Ok(json!({})) } "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")?)?; // important that this read is before we take the mutex, because it could be slow! let mut car_bytes: Vec = Default::default(); diff --git a/adenosine-pds/src/models.rs b/adenosine-pds/src/models.rs index 6c02a71..32f9f71 100644 --- a/adenosine-pds/src/models.rs +++ b/adenosine-pds/src/models.rs @@ -38,9 +38,35 @@ pub struct RepoDescribe { pub nameIsCorrect: bool, } +#[allow(non_snake_case)] +#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq)] +pub struct RepoCreateRecord { + pub did: String, + pub collection: String, + pub record: serde_json::Value, +} + +#[allow(non_snake_case)] +#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq)] +pub struct RepoPutRecord { + pub did: String, + pub collection: String, + pub rkey: String, + pub record: serde_json::Value, +} + +#[allow(non_snake_case)] +#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq)] +pub struct RepoDeleteRecord { + pub did: String, + pub collection: String, + pub rkey: String, +} + #[allow(non_snake_case)] #[derive(Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq)] pub struct RepoBatchWriteBody { + pub did: String, pub writes: Vec, } -- cgit v1.2.3