Updates endpoint to match latest Codex

This commit is contained in:
benbierens 2023-11-10 08:20:08 +01:00
parent b8ce4c49d6
commit c5cc15daa0
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
4 changed files with 53 additions and 5 deletions

View File

@ -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<CodexLocalDataResponse[]>("local");
}
public CodexSalesAvailabilityResponse SalesAvailability(CodexSalesAvailabilityRequest request)

View File

@ -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; }
}
}

View File

@ -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);
}
}
}

View File

@ -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);