refactor: use ipfs.dag().resolve in http
perhaps the error message requirements have changed, since this worked right away? aah nope, they must concern other uses of walk_path. well, this passes the tests either way.
This commit is contained in:
parent
08782f9b58
commit
981a67d781
@ -121,38 +121,23 @@ async fn inner_resolve<T: IpfsTypes>(
|
|||||||
ipfs: Ipfs<T>,
|
ipfs: Ipfs<T>,
|
||||||
opts: ResolveOptions,
|
opts: ResolveOptions,
|
||||||
) -> Result<impl Reply, Rejection> {
|
) -> Result<impl Reply, Rejection> {
|
||||||
use crate::v0::refs::{walk_path, IpfsPath, WalkOptions};
|
use ipfs::IpfsPath;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
let path = IpfsPath::try_from(opts.arg.as_str()).map_err(StringError::from)?;
|
let path = IpfsPath::try_from(opts.arg.as_str()).map_err(StringError::from)?;
|
||||||
|
|
||||||
let walk_opts = WalkOptions {
|
let (resolved, remaining) = ipfs
|
||||||
follow_dagpb_data: true,
|
.dag()
|
||||||
};
|
.resolve(path, /* FIXME: query */ true)
|
||||||
|
|
||||||
let (current, _, remaining) = walk_path(&ipfs, &walk_opts, path)
|
|
||||||
.maybe_timeout(opts.timeout.map(StringSerialized::into_inner))
|
.maybe_timeout(opts.timeout.map(StringSerialized::into_inner))
|
||||||
.await
|
.await
|
||||||
.map_err(StringError::from)?
|
.map_err(StringError::from)?
|
||||||
.map_err(StringError::from)?;
|
.map_err(StringError::from)?;
|
||||||
|
|
||||||
let remaining = {
|
let current = resolved.cid();
|
||||||
let slashes = remaining.len();
|
|
||||||
let mut buf =
|
|
||||||
String::with_capacity(remaining.iter().map(|s| s.len()).sum::<usize>() + slashes);
|
|
||||||
|
|
||||||
for piece in remaining.into_iter().rev() {
|
|
||||||
if !buf.is_empty() {
|
|
||||||
buf.push('/');
|
|
||||||
}
|
|
||||||
buf.push_str(&piece);
|
|
||||||
}
|
|
||||||
|
|
||||||
buf
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(reply::json(&json!({
|
Ok(reply::json(&json!({
|
||||||
"Cid": { "/": current.to_string() },
|
"Cid": { "/": current.to_string() },
|
||||||
"RemPath": remaining,
|
"RemPath": StringSerialized(remaining),
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user