Skip to content

Implemented Filestore api #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/CoreApi/DupsResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Ipfs.CoreApi;

namespace Ipfs.Http.CoreApi
{
/// <summary>
/// Model holding response from <see cref="FilestoreApi"/> Dups command.
/// </summary>
public class DupsResponse : IDupsResponse
{
/// <summary>
/// Any error in the <see cref="IFilestoreApi"/> Dups response.
/// </summary>
public string Err { get; set; }

/// <summary>
/// The error in the <see cref="IFilestoreApi"/> Dups response.
/// </summary>
public string Ref { get; set; }
}

}
50 changes: 50 additions & 0 deletions src/CoreApi/FilestoreApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Ipfs.CoreApi;
using Ipfs.Http.CoreApi;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Ipfs.Http
{
/// <inheritdoc/>
public class FilestoreApi : IFilestoreApi
{
private IpfsClient ipfs;

/// <inheritdoc/>
internal FilestoreApi(IpfsClient ipfs)
{
this.ipfs = ipfs;
}

/// <inheritdoc/>
public async Task<IFilestoreApiObjectResponse> ListAsync(string cid, bool fileOrder, CancellationToken token)
{
var json = await ipfs.DoCommandAsync("filestore/ls", token, cid, fileOrder.ToString());

return JsonConvert.DeserializeObject<FilestoreObjectResponse>(json);
}

/// <inheritdoc/>
public async Task<IFilestoreApiObjectResponse> VerifyObjectsAsync(string cid, bool fileOrder, CancellationToken token)
{
var json = await ipfs.DoCommandAsync("filestore/verify", token, cid, fileOrder.ToString());

return JsonConvert.DeserializeObject<FilestoreObjectResponse>(json);
}

/// <inheritdoc/>
public async Task<IDupsResponse> DupsAsync(CancellationToken token)
{
var json = await ipfs.DoCommandAsync("filestore/dups", token);

return JsonConvert.DeserializeObject<DupsResponse>(json);
}
}

}
18 changes: 18 additions & 0 deletions src/CoreApi/FilestoreKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Ipfs.CoreApi;
using Newtonsoft.Json;

namespace Ipfs.Http
{
/// <summary>
/// Model for the hold filestore key
/// </summary>
public class FilestoreKey : IFilesStoreKey
{
/// <summary>
/// Key value.
/// </summary>
[JsonProperty("/")]
public string _ { get; set; }
}

}
41 changes: 41 additions & 0 deletions src/CoreApi/FilestoreObjectResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Ipfs.CoreApi;

namespace Ipfs.Http
{
/// <summary>
/// Model holding response to <see cref="IFilestoreApi"/>.
/// </summary>
public class FilestoreObjectResponse : IFilestoreApiObjectResponse
{
/// <summary>
/// Holds any error message.
/// </summary>
public string ErrorMsg { get; set; }

/// <summary>
/// Path to the file
/// </summary>
public string FilePath { get; set; }

/// <summary>
/// The key to the Filestore.
/// </summary>
public FilestoreKey Key { get; set; }

/// <summary>
/// The response offset.
/// </summary>
public string Offset { get; set; }

/// <summary>
/// The size of the object.
/// </summary>
public string Size { get; set; }

/// <summary>
/// The object status.k
/// </summary>
public string Status { get; set; }
}

}
2 changes: 1 addition & 1 deletion src/CoreApi/KeyApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ internal KeyApi(IpfsClient ipfs)
throw new NotImplementedException();
}
}
}
}
5 changes: 5 additions & 0 deletions src/IpfsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public IpfsClient()
Dag = new DagApi(this);
Object = new ObjectApi(this);
FileSystem = new FileSystemApi(this);
FilestoreApi = new FilestoreApi(this);
Mfs = new MfsApi(this);
PubSub = new PubSubApi(this);
Key = new KeyApi(this);
Expand Down Expand Up @@ -163,6 +164,10 @@ public IpfsClient(string host)
/// <inheritdoc />
public IFileSystemApi FileSystem { get; private set; }


/// <inheritdoc />
public IFilestoreApi FilestoreApi { get; private set; }

/// <inheritdoc />
public IMfsApi Mfs { get; private set; }

Expand Down