2
0
mirror of synced 2025-02-26 23:10:29 +00:00

Update to new codex image

This commit is contained in:
Ben 2024-10-30 08:34:41 +01:00
parent acb0bf4f29
commit b8d6ac929b
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
7 changed files with 52 additions and 24 deletions

View File

@ -10,7 +10,7 @@ namespace CodexPlugin
public class ApiChecker public class ApiChecker
{ {
// <INSERT-OPENAPI-YAML-HASH> // <INSERT-OPENAPI-YAML-HASH>
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 OpenApiFilePath = "/codex/openapi.yaml";
private const string DisableEnvironmentVariable = "CODEXPLUGIN_DISABLE_APICHECK"; private const string DisableEnvironmentVariable = "CODEXPLUGIN_DISABLE_APICHECK";

View File

@ -63,10 +63,10 @@ namespace CodexPlugin
}); });
} }
public string UploadFile(FileStream fileStream, Action<Failure> onFailure) public string UploadFile(UploadInput uploadInput, Action<Failure> onFailure)
{ {
return OnCodex( return OnCodex(
api => api.UploadAsync(fileStream), api => api.UploadAsync(uploadInput.ContentType, uploadInput.ContentDisposition, uploadInput.FileStream),
CreateRetryConfig(nameof(UploadFile), onFailure)); CreateRetryConfig(nameof(UploadFile), onFailure));
} }
@ -82,7 +82,7 @@ namespace CodexPlugin
public LocalDatasetList LocalFiles() public LocalDatasetList LocalFiles()
{ {
return mapper.Map(OnCodex(api => api.ListDataAsync("", ""))); return mapper.Map(OnCodex(api => api.ListDataAsync()));
} }
public StorageAvailability SalesAvailability(StorageAvailability request) public StorageAvailability SalesAvailability(StorageAvailability request)
@ -261,4 +261,18 @@ namespace CodexPlugin
log.Log($"{GetName()} {msg}"); 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; }
}
} }

View File

@ -18,6 +18,7 @@ namespace CodexPlugin
DebugPeer GetDebugPeer(string peerId); DebugPeer GetDebugPeer(string peerId);
ContentId UploadFile(TrackedFile file); ContentId UploadFile(TrackedFile file);
ContentId UploadFile(TrackedFile file, Action<Failure> onFailure); ContentId UploadFile(TrackedFile file, Action<Failure> onFailure);
ContentId UploadFile(TrackedFile file, string contentType, string contentDisposition, Action<Failure> onFailure);
TrackedFile? DownloadContent(ContentId contentId, string fileLabel = ""); TrackedFile? DownloadContent(ContentId contentId, string fileLabel = "");
TrackedFile? DownloadContent(ContentId contentId, Action<Failure> onFailure, string fileLabel = ""); TrackedFile? DownloadContent(ContentId contentId, Action<Failure> onFailure, string fileLabel = "");
LocalDatasetList LocalFiles(); LocalDatasetList LocalFiles();
@ -138,6 +139,11 @@ namespace CodexPlugin
} }
public ContentId UploadFile(TrackedFile file, Action<Failure> onFailure) public ContentId UploadFile(TrackedFile file, Action<Failure> onFailure)
{
return UploadFile(file, "random-test-data", "random-test-data", onFailure);
}
public ContentId UploadFile(TrackedFile file, string contentType, string contentDisposition, Action<Failure> onFailure)
{ {
using var fileStream = File.OpenRead(file.Filename); using var fileStream = File.OpenRead(file.Filename);
var uniqueId = Guid.NewGuid().ToString(); var uniqueId = Guid.NewGuid().ToString();
@ -145,10 +151,11 @@ namespace CodexPlugin
hooks.OnFileUploading(uniqueId, size); 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, () => var measurement = Stopwatch.Measure(log, logMessage, () =>
{ {
return CodexAccess.UploadFile(fileStream, onFailure); return CodexAccess.UploadFile(input, onFailure);
}); });
var response = measurement.Value; var response = measurement.Value;

View File

@ -443,21 +443,6 @@ paths:
summary: "Lists manifest CIDs stored locally in node." summary: "Lists manifest CIDs stored locally in node."
tags: [ Data ] tags: [ Data ]
operationId: listData 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: responses:
"200": "200":
description: Retrieved list of content CIDs 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." 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 ] tags: [ Data ]
operationId: upload 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: requestBody:
content: content:
application/octet-stream: application/octet-stream:

View File

@ -135,7 +135,10 @@ namespace AutoClient
private async Task<ContentId> UploadStream(FileStream fileStream) private async Task<ContentId> UploadStream(FileStream fileStream)
{ {
log.Debug($"Uploading file..."); 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 (string.IsNullOrEmpty(response)) FrameworkAssert.Fail("Received empty response.");
if (response.StartsWith("Unable to store block")) FrameworkAssert.Fail("Node failed to store block."); if (response.StartsWith("Unable to store block")) FrameworkAssert.Fail("Node failed to store block.");

View File

@ -1,5 +1,6 @@
using CodexOpenApi; using CodexOpenApi;
using IdentityModel.Client; using IdentityModel.Client;
using Logging;
using Utils; using Utils;
namespace BiblioTech namespace BiblioTech
@ -8,11 +9,13 @@ namespace BiblioTech
{ {
private static readonly string nl = Environment.NewLine; private static readonly string nl = Environment.NewLine;
private readonly Configuration config; private readonly Configuration config;
private readonly ILog log;
private CodexApi? currentCodexNode; private CodexApi? currentCodexNode;
public CodexCidChecker(Configuration config) public CodexCidChecker(Configuration config, ILog log)
{ {
this.config = config; this.config = config;
this.log = log;
} }
public async Task<CheckResponse> PerformCheck(string cid) public async Task<CheckResponse> PerformCheck(string cid)
@ -150,6 +153,7 @@ namespace BiblioTech
} }
catch (Exception e) catch (Exception e)
{ {
log.Error(e.ToString());
return false; return false;
} }
} }

View File

@ -80,7 +80,7 @@ namespace BiblioTech
client = new DiscordSocketClient(); client = new DiscordSocketClient();
client.Log += ClientLog; client.Log += ClientLog;
var checker = new CodexCidChecker(Config); var checker = new CodexCidChecker(Config, Log);
var notifyCommand = new NotifyCommand(); var notifyCommand = new NotifyCommand();
var associateCommand = new UserAssociateCommand(notifyCommand); var associateCommand = new UserAssociateCommand(notifyCommand);
var sprCommand = new SprCommand(); var sprCommand = new SprCommand();