From 71f6c4758c20b1b3029e715c995c154f6148834e Mon Sep 17 00:00:00 2001 From: amaidniazi Date: Sun, 1 Sep 2024 10:23:39 +0100 Subject: [PATCH 1/7] added FilesStore api --- src/CoreApi/DupsResponse.cs | 21 ++++++++ src/CoreApi/FilestoreApi.cs | 68 ++++++++++++++++++++++++++ src/CoreApi/FilestoreObjectResponse.cs | 41 ++++++++++++++++ src/CoreApi/Key.cs | 18 +++++++ src/IpfsClient.cs | 4 ++ 5 files changed, 152 insertions(+) create mode 100644 src/CoreApi/DupsResponse.cs create mode 100644 src/CoreApi/FilestoreApi.cs create mode 100644 src/CoreApi/FilestoreObjectResponse.cs create mode 100644 src/CoreApi/Key.cs diff --git a/src/CoreApi/DupsResponse.cs b/src/CoreApi/DupsResponse.cs new file mode 100644 index 0000000..b983de4 --- /dev/null +++ b/src/CoreApi/DupsResponse.cs @@ -0,0 +1,21 @@ +using Ipfs.CoreApi; + +namespace Ipfs.Http.CoreApi +{ + /// + /// Model holding response from Dups command. + /// + public class DupsResponse : IDupsResponse + { + /// + /// Any error in the Dups response. + /// + public string Err { get; set; } + + /// + /// The error in the Dups response. + /// + public string Ref { get; set; } + } + +} diff --git a/src/CoreApi/FilestoreApi.cs b/src/CoreApi/FilestoreApi.cs new file mode 100644 index 0000000..d67a099 --- /dev/null +++ b/src/CoreApi/FilestoreApi.cs @@ -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 +{ + /// + /// Concrete implementation of . + /// + public class FilestoreApi : IFilestoreApi + { + private IpfsClient ipfs; + + internal FilestoreApi(IpfsClient ipfs) + { + this.ipfs = ipfs; + } + + /// + /// List async api for . + /// + /// + /// + /// + /// + public async Task ListAsync(string cid, CancellationToken token, bool fileOrder) + { + var json = await ipfs.DoCommandAsync("filestore/ls", token, cid, fileOrder.ToString()); + + return JsonConvert.DeserializeObject(json); + } + + /// + /// Object verification api for . + /// + /// + /// + /// + /// + public async Task VerifyObjectsAsync(string cid, bool fileOrder, CancellationToken token) + { + var json = await ipfs.DoCommandAsync("filestore/verify", token, cid, fileOrder.ToString()); + + return JsonConvert.DeserializeObject(json); + } + + /// + /// Executes Dups command in . + /// + /// + /// + public async Task DupsAsync(CancellationToken token) + { + var json = await ipfs.DoCommandAsync("filestore/dups", token); + + return JsonConvert.DeserializeObject(json); + } + } + +} diff --git a/src/CoreApi/FilestoreObjectResponse.cs b/src/CoreApi/FilestoreObjectResponse.cs new file mode 100644 index 0000000..3a6f00a --- /dev/null +++ b/src/CoreApi/FilestoreObjectResponse.cs @@ -0,0 +1,41 @@ +using Ipfs.CoreApi; + +namespace Ipfs.Http.CoreApi +{ + /// + /// Model holding response to . + /// + public class FilestoreObjectResponse : IFilesStoreApiObjectResponse + { + /// + /// Holds any error message. + /// + public string ErrorMsg { get; set; } + + /// + /// Path to the file + /// + public string FilePath { get; set; } + + /// + /// The key to the Filestore. + /// + public IFilesStoreKey Key { get; set; } + + /// + /// The response offset. + /// + public string Offset { get; set; } + + /// + /// The size of the object. + /// + public string Size { get; set; } + + /// + /// The object status.k + /// + public string Status { get; set; } + } + +} diff --git a/src/CoreApi/Key.cs b/src/CoreApi/Key.cs new file mode 100644 index 0000000..67559cb --- /dev/null +++ b/src/CoreApi/Key.cs @@ -0,0 +1,18 @@ +using Ipfs.CoreApi; +using Newtonsoft.Json; + +namespace Ipfs.Http.CoreApi +{ + /// + /// Model for the hold filestore key + /// + public class Key : IFilesStoreKey + { + /// + /// Key value. + /// + [JsonProperty("/")] + public string Value { get; set; } + } + +} diff --git a/src/IpfsClient.cs b/src/IpfsClient.cs index 62b1c1c..c67504d 100644 --- a/src/IpfsClient.cs +++ b/src/IpfsClient.cs @@ -163,6 +163,10 @@ public IpfsClient(string host) /// public IFileSystemApi FileSystem { get; private set; } + + /// + public IFilestoreApi FileSystem { get; private set; } + /// public IMfsApi Mfs { get; private set; } From 9fe4cb2b668b95a474000ccdb4db234549e3b5eb Mon Sep 17 00:00:00 2001 From: Amaid Niazi Date: Wed, 4 Sep 2024 07:03:27 +0100 Subject: [PATCH 2/7] Update src/IpfsClient.cs Co-authored-by: Arlo --- src/IpfsClient.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/IpfsClient.cs b/src/IpfsClient.cs index c67504d..75d3a75 100644 --- a/src/IpfsClient.cs +++ b/src/IpfsClient.cs @@ -165,7 +165,8 @@ public IpfsClient(string host) /// - public IFilestoreApi FileSystem { get; private set; } + public IFilestoreApi Filestore { get; private set; } + /// public IMfsApi Mfs { get; private set; } From 616f87bc5dfe752057b929b1d32e56fda8453e8f Mon Sep 17 00:00:00 2001 From: amaidniazi Date: Thu, 12 Sep 2024 19:19:52 +0100 Subject: [PATCH 3/7] Fixed deserialization for filestore --- src/CoreApi/FilestoreObjectResponse.cs | 3 ++- src/CoreApi/Key.cs | 2 +- src/CoreApi/KeyApi.cs | 2 +- src/IpfsClient.cs | 6 ++++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/CoreApi/FilestoreObjectResponse.cs b/src/CoreApi/FilestoreObjectResponse.cs index 3a6f00a..6389664 100644 --- a/src/CoreApi/FilestoreObjectResponse.cs +++ b/src/CoreApi/FilestoreObjectResponse.cs @@ -20,7 +20,8 @@ public class FilestoreObjectResponse : IFilesStoreApiObjectResponse /// /// The key to the Filestore. /// - public IFilesStoreKey Key { get; set; } + + public Key Key { get; set; } /// /// The response offset. diff --git a/src/CoreApi/Key.cs b/src/CoreApi/Key.cs index 67559cb..eb97d92 100644 --- a/src/CoreApi/Key.cs +++ b/src/CoreApi/Key.cs @@ -12,7 +12,7 @@ public class Key : IFilesStoreKey /// Key value. /// [JsonProperty("/")] - public string Value { get; set; } + public string _ { get; set; } } } diff --git a/src/CoreApi/KeyApi.cs b/src/CoreApi/KeyApi.cs index a152542..3eae143 100644 --- a/src/CoreApi/KeyApi.cs +++ b/src/CoreApi/KeyApi.cs @@ -114,4 +114,4 @@ internal KeyApi(IpfsClient ipfs) throw new NotImplementedException(); } } -} +} \ No newline at end of file diff --git a/src/IpfsClient.cs b/src/IpfsClient.cs index c67504d..c326b9b 100644 --- a/src/IpfsClient.cs +++ b/src/IpfsClient.cs @@ -1,4 +1,5 @@ using Ipfs.CoreApi; +using Ipfs.Http.CoreApi; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -73,6 +74,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); @@ -163,9 +165,9 @@ public IpfsClient(string host) /// public IFileSystemApi FileSystem { get; private set; } - + /// - public IFilestoreApi FileSystem { get; private set; } + public IFilestoreApi FilestoreApi { get; private set; } /// public IMfsApi Mfs { get; private set; } From 6b01a70d5ed2bccb61b3a095e2ccb7a2a79003f6 Mon Sep 17 00:00:00 2001 From: amaidniazi Date: Thu, 12 Sep 2024 19:37:13 +0100 Subject: [PATCH 4/7] removed test app code files --- TestApp/Program.cs | 42 ------------------------------------------ TestApp/TestApp.csproj | 18 ------------------ 2 files changed, 60 deletions(-) delete mode 100644 TestApp/Program.cs delete mode 100644 TestApp/TestApp.csproj diff --git a/TestApp/Program.cs b/TestApp/Program.cs deleted file mode 100644 index fbee6f9..0000000 --- a/TestApp/Program.cs +++ /dev/null @@ -1,42 +0,0 @@ -// See https://aka.ms/new-console-template for more information -using Ipfs.Http; -using OwlCore.Diagnostics; -using OwlCore.Kubo; -using OwlCore.Storage.System.IO; - - - -var res = await BootstrapKuboAsync(new SystemFolder("D:\\Projects\\_repo"), 9000, 9001, CancellationToken.None); -//await res.Client.Config.SetAsync("--json Experimental.FilestoreEnabled","true"); - -var result = await res.Client.FilestoreApi.DupsAsync(CancellationToken.None); - -Logger.MessageReceived += Logger_MessageReceived; - -void Logger_MessageReceived(object? sender, LoggerMessageEventArgs e) -{ - -} - - -//await ipfsClient.FilestoreApi.DupsAsync(CancellationToken.None); - -while (true) ; -async Task BootstrapKuboAsync(SystemFolder kuboRepo, int apiPort, int gatewayPort, CancellationToken cancellationToken) -{ - var kubo = new KuboBootstrapper(kuboRepo.Path) - { - ApiUri = new Uri($"http://127.0.0.1:{apiPort}"), - GatewayUri = new Uri($"http://127.0.0.1:{gatewayPort}"), - RoutingMode = DhtRoutingMode.None, - LaunchConflictMode = BootstrapLaunchConflictMode.Relaunch, - ApiUriMode = ConfigMode.OverwriteExisting, - GatewayUriMode = ConfigMode.OverwriteExisting, - BinaryWorkingFolder = new SystemFolder("D:\\ipfsBinary"), - - }; - - await kubo.StartAsync(cancellationToken); - - return kubo; -} \ No newline at end of file diff --git a/TestApp/TestApp.csproj b/TestApp/TestApp.csproj deleted file mode 100644 index 952602a..0000000 --- a/TestApp/TestApp.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - Exe - net8.0 - enable - enable - - - - - - - - - - - From 04233f6f1105df5c6d2c21d49f6a4826d4abbe35 Mon Sep 17 00:00:00 2001 From: Amaid Niazi Date: Sat, 21 Sep 2024 11:53:38 +0100 Subject: [PATCH 5/7] Update src/CoreApi/FilestoreObjectResponse.cs Co-authored-by: Arlo --- src/CoreApi/FilestoreObjectResponse.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CoreApi/FilestoreObjectResponse.cs b/src/CoreApi/FilestoreObjectResponse.cs index 6389664..561fef4 100644 --- a/src/CoreApi/FilestoreObjectResponse.cs +++ b/src/CoreApi/FilestoreObjectResponse.cs @@ -20,7 +20,6 @@ public class FilestoreObjectResponse : IFilesStoreApiObjectResponse /// /// The key to the Filestore. /// - public Key Key { get; set; } /// From d73f62d2b06865adb4a451dcc28253240ba1c940 Mon Sep 17 00:00:00 2001 From: amaidniazi Date: Sat, 21 Sep 2024 18:59:50 +0100 Subject: [PATCH 6/7] Code cleanup --- src/CoreApi/FilestoreApi.cs | 34 ++++++------------------- src/CoreApi/{Key.cs => FilestoreKey.cs} | 4 +-- src/CoreApi/FilestoreObjectResponse.cs | 6 ++--- src/IpfsClient.cs | 1 - 4 files changed, 13 insertions(+), 32 deletions(-) rename src/CoreApi/{Key.cs => FilestoreKey.cs} (80%) diff --git a/src/CoreApi/FilestoreApi.cs b/src/CoreApi/FilestoreApi.cs index d67a099..9476ffe 100644 --- a/src/CoreApi/FilestoreApi.cs +++ b/src/CoreApi/FilestoreApi.cs @@ -8,55 +8,37 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -using static Ipfs.Http.CoreApi.FilestoreApi; -namespace Ipfs.Http.CoreApi +namespace Ipfs.Http { - /// - /// Concrete implementation of . - /// + /// public class FilestoreApi : IFilestoreApi { private IpfsClient ipfs; + /// internal FilestoreApi(IpfsClient ipfs) { this.ipfs = ipfs; } - /// - /// List async api for . - /// - /// - /// - /// - /// - public async Task ListAsync(string cid, CancellationToken token, bool fileOrder) + /// + public async Task ListAsync(string cid, bool fileOrder, CancellationToken token) { var json = await ipfs.DoCommandAsync("filestore/ls", token, cid, fileOrder.ToString()); return JsonConvert.DeserializeObject(json); } - /// - /// Object verification api for . - /// - /// - /// - /// - /// - public async Task VerifyObjectsAsync(string cid, bool fileOrder, CancellationToken token) + /// + public async Task VerifyObjectsAsync(string cid, bool fileOrder, CancellationToken token) { var json = await ipfs.DoCommandAsync("filestore/verify", token, cid, fileOrder.ToString()); return JsonConvert.DeserializeObject(json); } - /// - /// Executes Dups command in . - /// - /// - /// + /// public async Task DupsAsync(CancellationToken token) { var json = await ipfs.DoCommandAsync("filestore/dups", token); diff --git a/src/CoreApi/Key.cs b/src/CoreApi/FilestoreKey.cs similarity index 80% rename from src/CoreApi/Key.cs rename to src/CoreApi/FilestoreKey.cs index eb97d92..e088f71 100644 --- a/src/CoreApi/Key.cs +++ b/src/CoreApi/FilestoreKey.cs @@ -1,12 +1,12 @@ using Ipfs.CoreApi; using Newtonsoft.Json; -namespace Ipfs.Http.CoreApi +namespace Ipfs.Http { /// /// Model for the hold filestore key /// - public class Key : IFilesStoreKey + public class FilestoreKey : IFilesStoreKey { /// /// Key value. diff --git a/src/CoreApi/FilestoreObjectResponse.cs b/src/CoreApi/FilestoreObjectResponse.cs index 6389664..11a2dde 100644 --- a/src/CoreApi/FilestoreObjectResponse.cs +++ b/src/CoreApi/FilestoreObjectResponse.cs @@ -1,11 +1,11 @@ using Ipfs.CoreApi; -namespace Ipfs.Http.CoreApi +namespace Ipfs.Http { /// /// Model holding response to . /// - public class FilestoreObjectResponse : IFilesStoreApiObjectResponse + public class FilestoreObjectResponse : IFilestoreApiObjectResponse { /// /// Holds any error message. @@ -21,7 +21,7 @@ public class FilestoreObjectResponse : IFilesStoreApiObjectResponse /// The key to the Filestore. /// - public Key Key { get; set; } + public FilestoreKey Key { get; set; } /// /// The response offset. diff --git a/src/IpfsClient.cs b/src/IpfsClient.cs index c326b9b..43d357a 100644 --- a/src/IpfsClient.cs +++ b/src/IpfsClient.cs @@ -1,5 +1,4 @@ using Ipfs.CoreApi; -using Ipfs.Http.CoreApi; using Newtonsoft.Json; using System; using System.Collections.Generic; From a12f990451ea94a8757b706e291eff1294c9c934 Mon Sep 17 00:00:00 2001 From: Arlo Date: Sat, 21 Sep 2024 17:49:07 -0500 Subject: [PATCH 7/7] Update src/CoreApi/FilestoreKey.cs --- src/CoreApi/FilestoreKey.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CoreApi/FilestoreKey.cs b/src/CoreApi/FilestoreKey.cs index e088f71..5267294 100644 --- a/src/CoreApi/FilestoreKey.cs +++ b/src/CoreApi/FilestoreKey.cs @@ -6,7 +6,7 @@ namespace Ipfs.Http /// /// Model for the hold filestore key /// - public class FilestoreKey : IFilesStoreKey + public class FilestoreKey : IFilestoreKey { /// /// Key value.