punching datastore functions through to API
This commit is contained in:
parent
dee4e1cab5
commit
d6e159c4de
11
src/dag.rs
11
src/dag.rs
@ -36,10 +36,15 @@ impl<Types: RepoTypes> IpldDag<Types> {
|
||||
Some(cid) => cid,
|
||||
None => return Err(anyhow::anyhow!("expected cid")),
|
||||
};
|
||||
let mut ipld = decode_ipld(&cid, self.repo.get_block(&cid).await?.data())?;
|
||||
for sub_path in path.iter() {}
|
||||
self.repo.pin_block(cid).await
|
||||
}
|
||||
|
||||
todo!()
|
||||
pub async fn unpin(&self, path: IpfsPath) -> Result<(), Error> {
|
||||
let cid = match path.root().cid() {
|
||||
Some(cid) => cid,
|
||||
None => return Err(anyhow::anyhow!("expected cid")),
|
||||
};
|
||||
self.repo.unpin_block(cid).await
|
||||
}
|
||||
|
||||
pub async fn get(&self, path: IpfsPath) -> Result<Ipld, Error> {
|
||||
|
@ -69,6 +69,7 @@ pub trait DataStore: Debug + Clone + Send + Sync + Unpin + 'static {
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum Column {
|
||||
Ipns,
|
||||
Pin,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -209,15 +210,15 @@ impl<TRepoTypes: RepoTypes> Repo<TRepoTypes> {
|
||||
self.data_store.remove(Column::Ipns, ipns.as_bytes()).await
|
||||
}
|
||||
|
||||
pub async fn pin_block(&self, ipns: &PeerId, cid: &Cid) -> Result<(), Error> {
|
||||
pub async fn pin_block(&self, cid: &Cid) -> Result<(), Error> {
|
||||
self.data_store
|
||||
.put(Column::Ipns, &cid.to_bytes(), &vec![1])
|
||||
.put(Column::Pin, &cid.to_bytes(), &vec![1])
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn unpin_block(&self, ipns: &PeerId, cid: &Cid) -> Result<(), Error> {
|
||||
pub async fn unpin_block(&self, cid: &Cid) -> Result<(), Error> {
|
||||
self.data_store
|
||||
.put(Column::Ipns, &cid.to_bytes(), &vec![0])
|
||||
.put(Column::Pin, &cid.to_bytes(), &vec![0])
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user