diff --git a/ProjectPlugins/CodexPlugin/CodexAccess.cs b/ProjectPlugins/CodexPlugin/CodexAccess.cs index 90d0dda..3d11abe 100644 --- a/ProjectPlugins/CodexPlugin/CodexAccess.cs +++ b/ProjectPlugins/CodexPlugin/CodexAccess.cs @@ -62,14 +62,17 @@ namespace CodexPlugin public string UploadFile(FileStream fileStream) { - // private const string UploadFailedMessage = "Unable to store block"; - - return Http().HttpPostStream("upload", fileStream); + return Http().HttpPostStream("data", fileStream); } public Stream DownloadFile(string contentId) { - return Http().HttpGetStream("download/" + contentId); + return Http().HttpGetStream("data/" + contentId); + } + + public CodexLocalDataResponse[] LocalFiles() + { + return Http().HttpGetJson("local"); } public CodexSalesAvailabilityResponse SalesAvailability(CodexSalesAvailabilityRequest request) diff --git a/ProjectPlugins/CodexPlugin/CodexApiTypes.cs b/ProjectPlugins/CodexPlugin/CodexApiTypes.cs index 49b0d2d..03e112f 100644 --- a/ProjectPlugins/CodexPlugin/CodexApiTypes.cs +++ b/ProjectPlugins/CodexPlugin/CodexApiTypes.cs @@ -170,4 +170,30 @@ namespace CodexPlugin { public string cid { get; set; } = string.Empty; } + + public class CodexLocalData + { + public CodexLocalData(ContentId cid, CodexLocalDataManifestResponse manifest) + { + Cid = cid; + Manifest = manifest; + } + + public ContentId Cid { get; } + public CodexLocalDataManifestResponse Manifest { get; } + } + + public class CodexLocalDataResponse + { + public string cid { get; set; } = string.Empty; + public CodexLocalDataManifestResponse manifest { get; set; } = new(); + } + + public class CodexLocalDataManifestResponse + { + public string rootHash { get; set; } = string.Empty; + public int originalBytes { get; set; } + public int blockSize { get; set; } + public bool @protected { get; set; } + } } diff --git a/ProjectPlugins/CodexPlugin/CodexNode.cs b/ProjectPlugins/CodexPlugin/CodexNode.cs index 1096a10..e688d5d 100644 --- a/ProjectPlugins/CodexPlugin/CodexNode.cs +++ b/ProjectPlugins/CodexPlugin/CodexNode.cs @@ -18,6 +18,7 @@ namespace CodexPlugin //CodexDebugRepoStoreResponse[] GetDebugRepoStore(); ContentId UploadFile(TrackedFile file); TrackedFile? DownloadContent(ContentId contentId, string fileLabel = ""); + CodexLocalData[] LocalFiles(); void ConnectToPeer(ICodexNode node); CodexDebugVersionResponse Version { get; } IMarketplaceAccess Marketplace { get; } @@ -121,6 +122,11 @@ namespace CodexPlugin return file; } + public CodexLocalData[] LocalFiles() + { + return CodexAccess.LocalFiles().Select(l => new CodexLocalData(new ContentId(l.cid), l.manifest)).ToArray(); + } + public void ConnectToPeer(ICodexNode node) { var peer = (CodexNode)node; @@ -205,5 +211,15 @@ namespace CodexPlugin } public string Id { get; } + + public override bool Equals(object? obj) + { + return obj is ContentId id && Id == id.Id; + } + + public override int GetHashCode() + { + return HashCode.Combine(Id); + } } } diff --git a/Tests/CodexTests/BasicTests/ExampleTests.cs b/Tests/CodexTests/BasicTests/ExampleTests.cs index b7e89e2..44c6dc6 100644 --- a/Tests/CodexTests/BasicTests/ExampleTests.cs +++ b/Tests/CodexTests/BasicTests/ExampleTests.cs @@ -16,7 +16,10 @@ namespace CodexTests.BasicTests { var primary = AddCodex(s => s.WithLogLevel(CodexLogLevel.Trace, new CodexLogCustomTopics(CodexLogLevel.Warn, CodexLogLevel.Warn))); - primary.UploadFile(GenerateTestFile(5.MB())); + var cid = primary.UploadFile(GenerateTestFile(5.MB())); + + var content = primary.LocalFiles(); + CollectionAssert.Contains(content.Select(c => c.Cid), cid); var log = Ci.DownloadLog(primary);