workaround for faulty local-dataset api match

This commit is contained in:
benbierens 2024-11-12 16:51:32 +01:00
parent 55cc0ab0ef
commit 833421b2b2
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
3 changed files with 82 additions and 2 deletions

View File

@ -82,7 +82,20 @@ namespace CodexPlugin
public LocalDatasetList LocalFiles() 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<LocalDatasetListJson>(str)!;
}, nameof(LocalFiles));
}));
} }
public StorageAvailability SalesAvailability(StorageAvailability request) public StorageAvailability SalesAvailability(StorageAvailability request)

View File

@ -140,7 +140,7 @@ namespace CodexPlugin
public ContentId UploadFile(TrackedFile file, Action<Failure> onFailure) public ContentId UploadFile(TrackedFile file, Action<Failure> 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<Failure> onFailure) public ContentId UploadFile(TrackedFile file, string contentType, string contentDisposition, Action<Failure> onFailure)

View File

@ -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) public LocalDatasetList Map(CodexOpenApi.DataList dataList)
{ {
return new LocalDatasetList 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) public CodexOpenApi.SalesAvailabilityCREATE Map(StorageAvailability availability)
{ {
return new CodexOpenApi.SalesAvailabilityCREATE 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<string, object> map, string name) private JArray JArray(IDictionary<string, object> map, string name)
{ {
return (JArray)map[name]; return (JArray)map[name];
@ -243,4 +272,42 @@ namespace CodexPlugin
return new ByteSize(Convert.ToInt64(size)); 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<LocalDatasetListJsonItem>();
}
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; }
}
} }