summaryrefslogtreecommitdiffstats
path: root/adenosine-pds/src
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2022-12-19 21:50:14 -0800
committerbryan newbold <bnewbold@robocracy.org>2022-12-20 00:29:58 -0800
commit2cd76edf9d418edce85ad624d99e2eb1d4bf267d (patch)
treefb116f774494ce3e43fcf4994031fd0fc27c0466 /adenosine-pds/src
parent8b6dc7a93d6aa37338aa49dfd28f754ad7ee2a23 (diff)
downloadadenosine-2cd76edf9d418edce85ad624d99e2eb1d4bf267d.tar.gz
adenosine-2cd76edf9d418edce85ad624d99e2eb1d4bf267d.zip
pds: for non-existant DID as an error, not panic
Diffstat (limited to 'adenosine-pds/src')
-rw-r--r--adenosine-pds/src/bsky.rs15
-rw-r--r--adenosine-pds/src/lib.rs1
2 files changed, 12 insertions, 4 deletions
diff --git a/adenosine-pds/src/bsky.rs b/adenosine-pds/src/bsky.rs
index ed4fe10..d2ae827 100644
--- a/adenosine-pds/src/bsky.rs
+++ b/adenosine-pds/src/bsky.rs
@@ -60,11 +60,15 @@ pub fn bsky_mutate_db(db: &mut AtpDatabase, did: &Did, mutations: Vec<Mutation>)
Ok(())
}
+// TODO: should probably return Result<Option<Profile>>?
pub fn bsky_get_profile(srv: &mut AtpService, did: &Did) -> Result<Profile> {
// first get the profile record
let mut profile_cid: Option<Cid> = None;
- let commit_cid = &srv.repo.lookup_commit(did)?.unwrap();
- let last_commit = srv.repo.get_commit(commit_cid)?;
+ let commit_cid = match srv.repo.lookup_commit(did)? {
+ Some(cid) => cid,
+ None => Err(anyhow!("repository not found: {}", did))?,
+ };
+ let last_commit = srv.repo.get_commit(&commit_cid)?;
let full_map = srv.repo.mst_to_map(&last_commit.mst_cid)?;
let prefix = "/app.bsky.actor.profile/";
for (mst_key, cid) in full_map.iter() {
@@ -115,8 +119,11 @@ pub fn bsky_get_profile(srv: &mut AtpService, did: &Did) -> Result<Profile> {
pub fn bsky_update_profile(srv: &mut AtpService, did: &Did, profile: ProfileRecord) -> Result<()> {
// get the profile record
let mut profile_tid: Option<Tid> = None;
- let commit_cid = &srv.repo.lookup_commit(did)?.unwrap();
- let last_commit = srv.repo.get_commit(commit_cid)?;
+ let commit_cid = match srv.repo.lookup_commit(did)? {
+ Some(cid) => cid,
+ None => Err(anyhow!("repository not found: {}", did))?,
+ };
+ let last_commit = srv.repo.get_commit(&commit_cid)?;
let full_map = srv.repo.mst_to_map(&last_commit.mst_cid)?;
let prefix = "/app.bsky.actor.profile/";
for (mst_key, _cid) in full_map.iter() {
diff --git a/adenosine-pds/src/lib.rs b/adenosine-pds/src/lib.rs
index 9721652..f855e59 100644
--- a/adenosine-pds/src/lib.rs
+++ b/adenosine-pds/src/lib.rs
@@ -444,6 +444,7 @@ fn xrpc_get_handler(
// TODO did or handle
let did = Did::from_str(&xrpc_required_param(request, "actor")?)?;
let mut srv = srv.lock().unwrap();
+ // TODO: if profile doesn't exist, return a 404
Ok(json!(bsky_get_profile(&mut srv, &did)?))
}
"app.bsky.actor.search" => {