From b8d6ac929b48481fe708fc6ee05ac66c086952a8 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 30 Oct 2024 08:34:41 +0100 Subject: [PATCH] Update to new codex image --- ProjectPlugins/CodexPlugin/ApiChecker.cs | 2 +- ProjectPlugins/CodexPlugin/CodexAccess.cs | 20 ++++++++++++--- ProjectPlugins/CodexPlugin/CodexNode.cs | 11 +++++++-- ProjectPlugins/CodexPlugin/openapi.yaml | 30 +++++++++++------------ Tools/AutoClient/Purchaser.cs | 5 +++- Tools/BiblioTech/CodexCidChecker.cs | 6 ++++- Tools/BiblioTech/Program.cs | 2 +- 7 files changed, 52 insertions(+), 24 deletions(-) diff --git a/ProjectPlugins/CodexPlugin/ApiChecker.cs b/ProjectPlugins/CodexPlugin/ApiChecker.cs index e5b584a..f021922 100644 --- a/ProjectPlugins/CodexPlugin/ApiChecker.cs +++ b/ProjectPlugins/CodexPlugin/ApiChecker.cs @@ -10,7 +10,7 @@ namespace CodexPlugin public class ApiChecker { // - private const string OpenApiYamlHash = "39-0C-32-A3-EA-90-4F-29-1C-67-12-F1-D5-BE-31-67-8D-90-43-1E-F2-02-63-5B-0C-49-F7-1E-E5-EC-F7-00"; + private const string OpenApiYamlHash = "09-53-C3-A6-31-A5-0C-8B-53-1C-3D-C7-2B-1E-85-C7-17-60-54-43-01-C4-49-4E-D9-68-35-7D-F7-41-13-B5"; private const string OpenApiFilePath = "/codex/openapi.yaml"; private const string DisableEnvironmentVariable = "CODEXPLUGIN_DISABLE_APICHECK"; diff --git a/ProjectPlugins/CodexPlugin/CodexAccess.cs b/ProjectPlugins/CodexPlugin/CodexAccess.cs index 922004e..e8f755c 100644 --- a/ProjectPlugins/CodexPlugin/CodexAccess.cs +++ b/ProjectPlugins/CodexPlugin/CodexAccess.cs @@ -63,10 +63,10 @@ namespace CodexPlugin }); } - public string UploadFile(FileStream fileStream, Action onFailure) + public string UploadFile(UploadInput uploadInput, Action onFailure) { return OnCodex( - api => api.UploadAsync(fileStream), + api => api.UploadAsync(uploadInput.ContentType, uploadInput.ContentDisposition, uploadInput.FileStream), CreateRetryConfig(nameof(UploadFile), onFailure)); } @@ -82,7 +82,7 @@ namespace CodexPlugin public LocalDatasetList LocalFiles() { - return mapper.Map(OnCodex(api => api.ListDataAsync("", ""))); + return mapper.Map(OnCodex(api => api.ListDataAsync())); } public StorageAvailability SalesAvailability(StorageAvailability request) @@ -261,4 +261,18 @@ namespace CodexPlugin log.Log($"{GetName()} {msg}"); } } + + public class UploadInput + { + public UploadInput(string contentType, string contentDisposition, FileStream fileStream) + { + ContentType = contentType; + ContentDisposition = contentDisposition; + FileStream = fileStream; + } + + public string ContentType { get; } + public string ContentDisposition { get; } + public FileStream FileStream { get; } + } } diff --git a/ProjectPlugins/CodexPlugin/CodexNode.cs b/ProjectPlugins/CodexPlugin/CodexNode.cs index f316e38..3c03369 100644 --- a/ProjectPlugins/CodexPlugin/CodexNode.cs +++ b/ProjectPlugins/CodexPlugin/CodexNode.cs @@ -18,6 +18,7 @@ namespace CodexPlugin DebugPeer GetDebugPeer(string peerId); ContentId UploadFile(TrackedFile file); ContentId UploadFile(TrackedFile file, Action onFailure); + ContentId UploadFile(TrackedFile file, string contentType, string contentDisposition, Action onFailure); TrackedFile? DownloadContent(ContentId contentId, string fileLabel = ""); TrackedFile? DownloadContent(ContentId contentId, Action onFailure, string fileLabel = ""); LocalDatasetList LocalFiles(); @@ -138,6 +139,11 @@ namespace CodexPlugin } public ContentId UploadFile(TrackedFile file, Action onFailure) + { + return UploadFile(file, "random-test-data", "random-test-data", onFailure); + } + + public ContentId UploadFile(TrackedFile file, string contentType, string contentDisposition, Action onFailure) { using var fileStream = File.OpenRead(file.Filename); var uniqueId = Guid.NewGuid().ToString(); @@ -145,10 +151,11 @@ namespace CodexPlugin hooks.OnFileUploading(uniqueId, size); - var logMessage = $"Uploading file {file.Describe()}..."; + var input = new UploadInput(contentType, contentDisposition, fileStream); + var logMessage = $"Uploading file {file.Describe()} with contentType: '{input.ContentType}' and disposition: '{input.ContentDisposition}'..."; var measurement = Stopwatch.Measure(log, logMessage, () => { - return CodexAccess.UploadFile(fileStream, onFailure); + return CodexAccess.UploadFile(input, onFailure); }); var response = measurement.Value; diff --git a/ProjectPlugins/CodexPlugin/openapi.yaml b/ProjectPlugins/CodexPlugin/openapi.yaml index dc0ad55..6d3dca9 100644 --- a/ProjectPlugins/CodexPlugin/openapi.yaml +++ b/ProjectPlugins/CodexPlugin/openapi.yaml @@ -443,21 +443,6 @@ paths: summary: "Lists manifest CIDs stored locally in node." tags: [ Data ] operationId: listData - parameters: - - name: content-type - in: header - required: false - description: The content type of the file. Must be valid. - schema: - type: string - example: "image/png" - - name: content-disposition - in: header - required: false - description: The content disposition used to send the filename. - schema: - type: string - example: "attachment; filename=\"codex.png\"" responses: "200": description: Retrieved list of content CIDs @@ -478,6 +463,21 @@ paths: summary: "Upload a file in a streaming manner. Once finished, the file is stored in the node and can be retrieved by any node in the network using the returned CID." tags: [ Data ] operationId: upload + parameters: + - name: content-type + in: header + required: false + description: The content type of the file. Must be valid. + schema: + type: string + example: "image/png" + - name: content-disposition + in: header + required: false + description: The content disposition used to send the filename. + schema: + type: string + example: "attachment; filename=\"codex.png\"" requestBody: content: application/octet-stream: diff --git a/Tools/AutoClient/Purchaser.cs b/Tools/AutoClient/Purchaser.cs index 97f9061..d31d91d 100644 --- a/Tools/AutoClient/Purchaser.cs +++ b/Tools/AutoClient/Purchaser.cs @@ -135,7 +135,10 @@ namespace AutoClient private async Task UploadStream(FileStream fileStream) { log.Debug($"Uploading file..."); - var response = await codex.UploadAsync(fileStream, app.Cts.Token); + var response = await codex.UploadAsync( + content_type: "autoclient-test-content", + content_disposition: "autoclient-test-content", + fileStream, app.Cts.Token); if (string.IsNullOrEmpty(response)) FrameworkAssert.Fail("Received empty response."); if (response.StartsWith("Unable to store block")) FrameworkAssert.Fail("Node failed to store block."); diff --git a/Tools/BiblioTech/CodexCidChecker.cs b/Tools/BiblioTech/CodexCidChecker.cs index 21ebc33..7c8e5dc 100644 --- a/Tools/BiblioTech/CodexCidChecker.cs +++ b/Tools/BiblioTech/CodexCidChecker.cs @@ -1,5 +1,6 @@ using CodexOpenApi; using IdentityModel.Client; +using Logging; using Utils; namespace BiblioTech @@ -8,11 +9,13 @@ namespace BiblioTech { private static readonly string nl = Environment.NewLine; private readonly Configuration config; + private readonly ILog log; private CodexApi? currentCodexNode; - public CodexCidChecker(Configuration config) + public CodexCidChecker(Configuration config, ILog log) { this.config = config; + this.log = log; } public async Task PerformCheck(string cid) @@ -150,6 +153,7 @@ namespace BiblioTech } catch (Exception e) { + log.Error(e.ToString()); return false; } } diff --git a/Tools/BiblioTech/Program.cs b/Tools/BiblioTech/Program.cs index ee258e3..46dee29 100644 --- a/Tools/BiblioTech/Program.cs +++ b/Tools/BiblioTech/Program.cs @@ -80,7 +80,7 @@ namespace BiblioTech client = new DiscordSocketClient(); client.Log += ClientLog; - var checker = new CodexCidChecker(Config); + var checker = new CodexCidChecker(Config, Log); var notifyCommand = new NotifyCommand(); var associateCommand = new UserAssociateCommand(notifyCommand); var sprCommand = new SprCommand();