aboutsummaryrefslogtreecommitdiffstats
path: root/adenosine-pds/src
diff options
context:
space:
mode:
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" => {