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 1 commit
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; }
}

}
68 changes: 68 additions & 0 deletions src/CoreApi/FilestoreApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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;
using static Ipfs.Http.CoreApi.FilestoreApi;

namespace Ipfs.Http.CoreApi
{
/// <summary>
/// Concrete implementation of <see cref="IFilestoreApi"/>.
/// </summary>
public class FilestoreApi : IFilestoreApi
{
private IpfsClient ipfs;

internal FilestoreApi(IpfsClient ipfs)
{
this.ipfs = ipfs;
}

/// <summary>
/// List async api for <see cref="IFilestoreApi"/>.
/// </summary>
/// <param name="cid"></param>
/// <param name="token"></param>
/// <param name="fileOrder"></param>
/// <returns></returns>
public async Task<IFilesStoreApiObjectResponse> ListAsync(string cid, CancellationToken token, bool fileOrder)
{
var json = await ipfs.DoCommandAsync("filestore/ls", token, cid, fileOrder.ToString());

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

/// <summary>
/// Object verification api for <see cref="IFilestoreApi"/>.
/// </summary>
/// <param name="cid"></param>
/// <param name="fileOrder"></param>
/// <param name="token"></param>
/// <returns></returns>
public async Task<IFilesStoreApiObjectResponse> VerifyObjectsAsync(string cid, bool fileOrder, CancellationToken token)
{
var json = await ipfs.DoCommandAsync("filestore/verify", token, cid, fileOrder.ToString());

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

/// <summary>
/// Executes Dups command in <see cref="IFilestoreApi"/>.
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
public async Task<IDupsResponse> DupsAsync(CancellationToken token)
{
var json = await ipfs.DoCommandAsync("filestore/dups", token);

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

}
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.CoreApi
{
/// <summary>
/// Model holding response to <see cref="IFilestoreApi"/>.
/// </summary>
public class FilestoreObjectResponse : IFilesStoreApiObjectResponse
{
/// <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 IFilesStoreKey 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; }
}

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

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

}
4 changes: 4 additions & 0 deletions src/IpfsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ public IpfsClient(string host)
/// <inheritdoc />
public IFileSystemApi FileSystem { get; private set; }


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

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

Expand Down