Lines up new openAPI.yaml

This commit is contained in:
Ben 2024-03-26 14:07:06 +01:00
parent f57188914e
commit bce9a2c124
No known key found for this signature in database
GPG Key ID: 541B9D8C9F1426A1
7 changed files with 55 additions and 13 deletions

View File

@ -2,6 +2,9 @@
{ {
public class ByteSize public class ByteSize
{ {
public static readonly ByteSize Zero = new ByteSize(0);
public const double DefaultSecondsPerMB = 10.0;
public ByteSize(long sizeInBytes) public ByteSize(long sizeInBytes)
{ {
if (sizeInBytes < 0) throw new ArgumentException("Cannot create ByteSize object with size less than 0. Was: " + sizeInBytes); if (sizeInBytes < 0) throw new ArgumentException("Cannot create ByteSize object with size less than 0. Was: " + sizeInBytes);
@ -10,7 +13,6 @@
public long SizeInBytes { get; } public long SizeInBytes { get; }
public const double DefaultSecondsPerMB = 10.0;
public long ToMB() public long ToMB()
{ {

View File

@ -70,7 +70,7 @@ namespace CodexPlugin
return fileResponse.Stream; return fileResponse.Stream;
} }
public LocalDataset[] LocalFiles() public LocalDatasetList LocalFiles()
{ {
return Map(OnCodex(api => api.ListDataAsync())); return Map(OnCodex(api => api.ListDataAsync()));
} }
@ -85,9 +85,7 @@ namespace CodexPlugin
public string RequestStorage(StoragePurchaseRequest request) public string RequestStorage(StoragePurchaseRequest request)
{ {
var body = Map(request); var body = Map(request);
throw new Exception("todo"); return OnCodex<string>(api => api.CreateStorageRequestAsync(request.ContentId.Id, body));
var read = ""; /* fix incoming*/ OnCodex<string>(api => api.CreateStorageRequestAsync(request.ContentId.Id, body));
return read;
} }
public StoragePurchase GetPurchaseStatus(string purchaseId) public StoragePurchase GetPurchaseStatus(string purchaseId)

View File

@ -16,7 +16,7 @@ namespace CodexPlugin
DebugPeer GetDebugPeer(string peerId); DebugPeer GetDebugPeer(string peerId);
ContentId UploadFile(TrackedFile file); ContentId UploadFile(TrackedFile file);
TrackedFile? DownloadContent(ContentId contentId, string fileLabel = ""); TrackedFile? DownloadContent(ContentId contentId, string fileLabel = "");
LocalDataset[] LocalFiles(); LocalDatasetList LocalFiles();
void ConnectToPeer(ICodexNode node); void ConnectToPeer(ICodexNode node);
DebugInfoVersion Version { get; } DebugInfoVersion Version { get; }
IMarketplaceAccess Marketplace { get; } IMarketplaceAccess Marketplace { get; }
@ -119,7 +119,7 @@ namespace CodexPlugin
return file; return file;
} }
public LocalDataset[] LocalFiles() public LocalDatasetList LocalFiles()
{ {
return CodexAccess.LocalFiles(); return CodexAccess.LocalFiles();
} }

View File

@ -1,4 +1,5 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using Utils;
namespace CodexPlugin namespace CodexPlugin
{ {
@ -50,9 +51,23 @@ namespace CodexPlugin
public string[] Addresses { get; set; } = Array.Empty<string>(); public string[] Addresses { get; set; } = Array.Empty<string>();
} }
public class LocalDatasetList
{
public LocalDataset[] Content { get; set; } = Array.Empty<LocalDataset>();
}
public class LocalDataset public class LocalDataset
{ {
public ContentId Cid { get; set; } = new ContentId(); public ContentId Cid { get; set; } = new();
public Manifest Manifest { get; set; } = new();
}
public class Manifest
{
public string RootHash { get; set; } = string.Empty;
public ByteSize OriginalBytes { get; set; } = ByteSize.Zero;
public ByteSize BlockSize { get; set; } = ByteSize.Zero;
public bool Protected { get; set; }
} }
public class SalesRequestStorageRequest public class SalesRequestStorageRequest

View File

@ -1,6 +1,7 @@
using CodexContractsPlugin; using CodexContractsPlugin;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.Numerics; using System.Numerics;
using Utils;
namespace CodexPlugin namespace CodexPlugin
{ {
@ -19,10 +20,21 @@ namespace CodexPlugin
}; };
} }
public LocalDataset[] Map(ICollection<CodexOpenApi.DataList> dataList) public LocalDatasetList Map(CodexOpenApi.DataList dataList)
{ {
throw new Exception("todo"); return new LocalDatasetList
return Array.Empty<LocalDataset>(); {
Content = dataList.Content.Select(Map).ToArray()
};
}
public LocalDataset Map(CodexOpenApi.DataItem dataItem)
{
return new LocalDataset
{
Cid = new ContentId(dataItem.Cid),
Manifest = MapManifest(dataItem.Manifest)
};
} }
public CodexOpenApi.SalesAvailabilityCREATE Map(StorageAvailability availability) public CodexOpenApi.SalesAvailabilityCREATE Map(StorageAvailability availability)
@ -105,6 +117,17 @@ namespace CodexPlugin
}; };
} }
private Manifest MapManifest(CodexOpenApi.ManifestItem manifest)
{
return new Manifest
{
BlockSize = new ByteSize(Convert.ToInt64(manifest.BlockSize)),
OriginalBytes = new ByteSize(Convert.ToInt64(manifest.OriginalBytes)),
RootHash = manifest.RootHash,
Protected = manifest.Protected
};
}
private JArray JArray(IDictionary<string, object> map, string name) private JArray JArray(IDictionary<string, object> map, string name)
{ {
return (JArray)map[name]; return (JArray)map[name];

View File

@ -632,6 +632,10 @@ paths:
responses: responses:
"200": "200":
description: Returns the Request ID as decimal string description: Returns the Request ID as decimal string
content:
text/plain:
schema:
type: string
"400": "400":
description: Invalid or missing Request ID description: Invalid or missing Request ID
"404": "404":

View File

@ -20,8 +20,8 @@ namespace CodexTests.BasicTests
var cid = primary.UploadFile(GenerateTestFile(5.MB())); var cid = primary.UploadFile(GenerateTestFile(5.MB()));
var content = primary.LocalFiles(); var localDatasets = primary.LocalFiles();
CollectionAssert.Contains(content.Select(c => c.Cid), cid); CollectionAssert.Contains(localDatasets.Content.Select(c => c.Cid), cid);
var log = Ci.DownloadLog(primary); var log = Ci.DownloadLog(primary);