Skip to content

Commit b510a8c

Browse files
committed
graph: remove /ipfs/ prefix when using file link resolver
1 parent 39f60ac commit b510a8c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

graph/src/components/link_resolver/file.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ impl FileLinkResolver {
4949
}
5050
}
5151

52+
pub fn remove_prefix(link: &str) -> &str {
53+
if link.starts_with("/ipfs/") {
54+
&link[6..] // Skip the "/ipfs/" prefix (6 characters)
55+
} else {
56+
link
57+
}
58+
}
59+
5260
#[async_trait]
5361
impl LinkResolverTrait for FileLinkResolver {
5462
fn with_timeout(&self, timeout: Duration) -> Box<dyn LinkResolverTrait> {
@@ -62,9 +70,10 @@ impl LinkResolverTrait for FileLinkResolver {
6270
}
6371

6472
async fn cat(&self, logger: &Logger, link: &Link) -> Result<Vec<u8>, Error> {
65-
let path = self.resolve_path(&link.link);
73+
let link = remove_prefix(&link.link);
74+
let path = self.resolve_path(&link);
6675

67-
slog::trace!(logger, "File resolver: reading file";
76+
slog::debug!(logger, "File resolver: reading file";
6877
"path" => path.to_string_lossy().to_string());
6978

7079
match tokio::fs::read(&path).await {

0 commit comments

Comments
 (0)