diff --git a/ProjectPlugins/CodexPlugin/CodexAccess.cs b/ProjectPlugins/CodexPlugin/CodexAccess.cs index e8f755c..f2f69d8 100644 --- a/ProjectPlugins/CodexPlugin/CodexAccess.cs +++ b/ProjectPlugins/CodexPlugin/CodexAccess.cs @@ -82,7 +82,20 @@ namespace CodexPlugin public LocalDatasetList LocalFiles() { - return mapper.Map(OnCodex(api => api.ListDataAsync())); + // API for listData mismatches. + //return mapper.Map(OnCodex(api => api.ListDataAsync())); + + return mapper.Map(CrashCheck(() => + { + var endpoint = GetEndpoint(); + return Time.Retry(() => + { + var str = endpoint.HttpGetString("data"); + if (string.IsNullOrEmpty(str)) throw new Exception("Empty response."); + return JsonConvert.DeserializeObject(str)!; + }, nameof(LocalFiles)); + })); + } public StorageAvailability SalesAvailability(StorageAvailability request) diff --git a/ProjectPlugins/CodexPlugin/CodexNode.cs b/ProjectPlugins/CodexPlugin/CodexNode.cs index 30b2442..58f1c3d 100644 --- a/ProjectPlugins/CodexPlugin/CodexNode.cs +++ b/ProjectPlugins/CodexPlugin/CodexNode.cs @@ -140,7 +140,7 @@ namespace CodexPlugin public ContentId UploadFile(TrackedFile file, Action onFailure) { - return UploadFile(file, "application/octet-stream", $"attachment; filename=\"{file.Filename}\"", onFailure); + return UploadFile(file, "application/octet-stream", $"attachment; filename=\"{Path.GetFileName(file.Filename)}\"", onFailure); } public ContentId UploadFile(TrackedFile file, string contentType, string contentDisposition, Action onFailure) diff --git a/ProjectPlugins/CodexPlugin/Mapper.cs b/ProjectPlugins/CodexPlugin/Mapper.cs index 9908169..7994d49 100644 --- a/ProjectPlugins/CodexPlugin/Mapper.cs +++ b/ProjectPlugins/CodexPlugin/Mapper.cs @@ -21,6 +21,14 @@ namespace CodexPlugin }; } + public LocalDatasetList Map(LocalDatasetListJson json) + { + return new LocalDatasetList + { + Content = json.Content.Select(Map).ToArray() + }; + } + public LocalDatasetList Map(CodexOpenApi.DataList dataList) { return new LocalDatasetList @@ -38,6 +46,15 @@ namespace CodexPlugin }; } + public LocalDataset Map(LocalDatasetListJsonItem item) + { + return new LocalDataset + { + Cid = new ContentId(item.Cid), + Manifest = MapManifest(item.Manifest) + }; + } + public CodexOpenApi.SalesAvailabilityCREATE Map(StorageAvailability availability) { return new CodexOpenApi.SalesAvailabilityCREATE @@ -188,6 +205,18 @@ namespace CodexPlugin }; } + public Manifest MapManifest(LocalDatasetListJsonItemManifest manifest) + { + return new Manifest + { + // needs update + BlockSize = new ByteSize(Convert.ToInt64(manifest.BlockSize)), + OriginalBytes = new ByteSize(Convert.ToInt64(manifest.DatasetSize)), + RootHash = manifest.TreeCid, + Protected = manifest.Protected + }; + } + private JArray JArray(IDictionary map, string name) { return (JArray)map[name]; @@ -243,4 +272,42 @@ namespace CodexPlugin return new ByteSize(Convert.ToInt64(size)); } } + + +//"content": [ +// { +// "cid": "zDvZRwzkxLxVaGces3kpkHjo8EcTPXudvYMfNxdoH21Ask1Js5fJ", +// "manifest": { +// "treeCid": "zDzSvJTf8GBRyEDNuAzXS9VnRfh8cNuYuRPwTLW6RUQReSgKnhCt", +// "datasetSize": 5242880, +// "blockSize": 65536, +// "filename": null, +// "mimetype": "application/octet-stream", +// "uploadedAt": 1731426230, +// "protected": false +// } +// } +// ] + + public class LocalDatasetListJson + { + public LocalDatasetListJsonItem[] Content { get; set; } = Array.Empty(); + } + + public class LocalDatasetListJsonItem + { + public string Cid { get; set; } = string.Empty; + public LocalDatasetListJsonItemManifest Manifest { get; set; } = new(); + } + + public class LocalDatasetListJsonItemManifest + { + public string TreeCid { get; set; } = string.Empty; + public int DatasetSize { get; set; } + public int BlockSize { get; set; } + public string? Filename { get; set; } = string.Empty; + public string? MimeType { get; set; } = string.Empty; + public int? UploadedAt { get; set; } + public bool Protected { get; set; } + } }