mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-01-09 17:03:08 +00:00
working local
This commit is contained in:
parent
c785df3adf
commit
8af91ea74b
@ -5,32 +5,46 @@ using Utils;
|
||||
|
||||
namespace DevconBoothImages
|
||||
{
|
||||
public class Codexes
|
||||
{
|
||||
public Codexes(CodexApi local, CodexApi testnet)
|
||||
{
|
||||
Local = local;
|
||||
Testnet = testnet;
|
||||
}
|
||||
|
||||
public CodexApi Local { get; }
|
||||
public CodexApi Testnet { get; }
|
||||
}
|
||||
|
||||
public class CodexWrapper
|
||||
{
|
||||
public async Task<List<CodexApi>> GetCodexes()
|
||||
public async Task<Codexes> GetCodexes()
|
||||
{
|
||||
var config = new Configuration();
|
||||
var result = new List<CodexApi>();
|
||||
return new Codexes(
|
||||
await GetCodex(config.CodexLocalEndpoint),
|
||||
await GetCodex(config.CodexPublicEndpoint)
|
||||
);
|
||||
}
|
||||
|
||||
foreach (var endpoint in config.CodexEndpoints)
|
||||
{
|
||||
var splitIndex = endpoint.LastIndexOf(':');
|
||||
var host = endpoint.Substring(0, splitIndex);
|
||||
var port = Convert.ToInt32(endpoint.Substring(splitIndex + 1));
|
||||
private async Task<CodexApi> GetCodex(string endpoint)
|
||||
{
|
||||
var splitIndex = endpoint.LastIndexOf(':');
|
||||
var host = endpoint.Substring(0, splitIndex);
|
||||
var port = Convert.ToInt32(endpoint.Substring(splitIndex + 1));
|
||||
|
||||
var address = new Address(
|
||||
host: host,
|
||||
port: port
|
||||
);
|
||||
var address = new Address(
|
||||
host: host,
|
||||
port: port
|
||||
);
|
||||
|
||||
var client = new HttpClient();
|
||||
var codex = new CodexApi(client);
|
||||
codex.BaseUrl = $"{address.Host}:{address.Port}/api/codex/v1";
|
||||
var client = new HttpClient();
|
||||
var codex = new CodexApi(client);
|
||||
codex.BaseUrl = $"{address.Host}:{address.Port}/api/codex/v1";
|
||||
|
||||
await CheckCodex(codex, endpoint);
|
||||
}
|
||||
|
||||
return result;
|
||||
await CheckCodex(codex, endpoint);
|
||||
return codex;
|
||||
}
|
||||
|
||||
private async Task CheckCodex(CodexApi codex, string endpoint)
|
||||
|
||||
@ -2,11 +2,8 @@
|
||||
{
|
||||
public class Configuration
|
||||
{
|
||||
public string[] CodexEndpoints { get; } =
|
||||
[
|
||||
"aaaa",
|
||||
"bbbb"
|
||||
];
|
||||
public string CodexLocalEndpoint { get; } = "http://localhost:8080";
|
||||
public string CodexPublicEndpoint { get; } = "";
|
||||
|
||||
public string AuthUser { get; } = "";
|
||||
public string AuthPw { get; } = "";
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using AutoClient;
|
||||
using CodexOpenApi;
|
||||
using Logging;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
@ -11,7 +12,8 @@ namespace DevconBoothImages
|
||||
private readonly Configuration config = new Configuration();
|
||||
private readonly CodexWrapper codexWrapper = new CodexWrapper();
|
||||
private readonly ImageGenerator imageGenerator = new ImageGenerator(new NullLog());
|
||||
private string[] currentCids = Array.Empty<string>();
|
||||
private string currentLocalCid = string.Empty;
|
||||
private string currentPublicCid = string.Empty;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
@ -62,52 +64,54 @@ namespace DevconBoothImages
|
||||
|
||||
private async Task UploadToCodexes(string filename, string shortName)
|
||||
{
|
||||
var result = new List<string>();
|
||||
var codexes = await codexWrapper.GetCodexes();
|
||||
try
|
||||
{
|
||||
foreach (var codex in codexes)
|
||||
{
|
||||
using (var fileStream = File.OpenRead(filename))
|
||||
{
|
||||
var response = await codex.UploadAsync(
|
||||
"application/image??",
|
||||
"attachement filanem???",
|
||||
fileStream);
|
||||
|
||||
if (string.IsNullOrEmpty(response) ||
|
||||
response.ToLowerInvariant().Contains("unable to store block"))
|
||||
{
|
||||
MessageBox.Show("Unable to upload image. Response empty or error message.");
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
currentLocalCid = await UploadFile(filename, shortName, codexes.Local);
|
||||
currentPublicCid = await UploadFile(filename, shortName, codexes.Testnet);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Upload failed: " + ex);
|
||||
}
|
||||
Log($"Generated {result.Count} CIDs");
|
||||
currentCids = result.ToArray();
|
||||
Log($"Generated CIDs");
|
||||
}
|
||||
|
||||
private async Task<string> UploadFile(string filename, string shortName, CodexApi codex)
|
||||
{
|
||||
using (var fileStream = File.OpenRead(filename))
|
||||
{
|
||||
var response = await codex.UploadAsync(
|
||||
"image/jpeg",
|
||||
$"attachment; filename=\"{shortName}\"",
|
||||
fileStream);
|
||||
|
||||
if (string.IsNullOrEmpty(response) ||
|
||||
response.ToLowerInvariant().Contains("unable to store block"))
|
||||
{
|
||||
throw new Exception("Unable to upload image. Response empty or error message.");
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
private void InfoToClipboard()
|
||||
{
|
||||
Clipboard.Clear();
|
||||
if (!currentCids.Any())
|
||||
if (string.IsNullOrEmpty(currentLocalCid) || string.IsNullOrEmpty(currentPublicCid))
|
||||
{
|
||||
Log("No CIDs were generated! Clipboard cleared.");
|
||||
return;
|
||||
}
|
||||
|
||||
var nl = Environment.NewLine;
|
||||
var msg =
|
||||
"";
|
||||
|
||||
|
||||
$"** Codex@Devcon 💻 Raspberry Pi Challenge **{nl}" +
|
||||
$"📢 A new image is available. Download it and bring it to the booth!{nl}" +
|
||||
$"Public Testnet CID: `{currentPublicCid}`{nl}" +
|
||||
$"Local Devcon network CID: `{currentLocalCid}`{nl}" +
|
||||
$"Setup instructions: [Here](https://docs.codex.storage){nl}" +
|
||||
$"Local Devcon network information: [Here](todo)";
|
||||
|
||||
Clipboard.SetText(msg);
|
||||
Log("CID info copied to clipboard. Paste it in Discord plz!");
|
||||
@ -118,4 +122,4 @@ namespace DevconBoothImages
|
||||
Txt.Text = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user