mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-02-04 21:33:05 +00:00
Adds debug messages for upload check
This commit is contained in:
parent
9540e97e2d
commit
fc9aa0726c
@ -47,13 +47,14 @@
|
||||
var result = "";
|
||||
while (result.Length < requiredLength)
|
||||
{
|
||||
var len = Math.Min(1024, requiredLength - result.Length);
|
||||
var remaining = requiredLength - result.Length;
|
||||
var len = Math.Min(1024, remaining);
|
||||
var bytes = new byte[len];
|
||||
random.NextBytes(bytes);
|
||||
result += string.Join("", bytes.Select(b => b.ToString()));
|
||||
}
|
||||
|
||||
return result;
|
||||
return result.Substring(0, Convert.ToInt32(requiredLength));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,6 +15,8 @@ namespace BiblioTech.CodexChecking
|
||||
Task CouldNotDownloadCid();
|
||||
Task GiveCidToUser(string cid);
|
||||
Task GiveDataFileToUser(string fileContent);
|
||||
|
||||
Task ToAdminChannel(string msg);
|
||||
}
|
||||
|
||||
public class CodexTwoWayChecker
|
||||
@ -91,9 +93,9 @@ namespace BiblioTech.CodexChecking
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsManifestLengthCompatible(check, manifest))
|
||||
if (await IsManifestLengthCompatible(handler, check, manifest))
|
||||
{
|
||||
if (IsContentCorrect(check, receivedCid))
|
||||
if (await IsContentCorrect(handler, check, receivedCid))
|
||||
{
|
||||
CheckNowCompleted(handler, check, userId);
|
||||
return;
|
||||
@ -148,34 +150,38 @@ namespace BiblioTech.CodexChecking
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsManifestLengthCompatible(TransferCheck check, Manifest manifest)
|
||||
private async Task<bool> IsManifestLengthCompatible(ICheckResponseHandler handler, TransferCheck check, Manifest manifest)
|
||||
{
|
||||
var dataLength = check.UniqueData.Length;
|
||||
var manifestLength = manifest.OriginalBytes.SizeInBytes;
|
||||
|
||||
await handler.ToAdminChannel($"Debug:dataLength={dataLength},manifestLength={manifestLength}");
|
||||
|
||||
return
|
||||
manifestLength > (dataLength - 1) &&
|
||||
manifestLength < (dataLength + 1);
|
||||
}
|
||||
|
||||
private bool IsContentCorrect(TransferCheck check, string receivedCid)
|
||||
private async Task<bool> IsContentCorrect(ICheckResponseHandler handler, TransferCheck check, string receivedCid)
|
||||
{
|
||||
try
|
||||
{
|
||||
return codexWrapper.OnCodex(node =>
|
||||
var content = codexWrapper.OnCodex(node =>
|
||||
{
|
||||
var file = node.DownloadContent(new ContentId(receivedCid));
|
||||
if (file == null) return false;
|
||||
if (file == null) return string.Empty;
|
||||
try
|
||||
{
|
||||
var content = File.ReadAllText(file.Filename).Trim();
|
||||
return content == check.UniqueData;
|
||||
return File.ReadAllText(file.Filename).Trim();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (File.Exists(file.Filename)) File.Delete(file.Filename);
|
||||
}
|
||||
});
|
||||
|
||||
await handler.ToAdminChannel($"Debug:content=`{content}`,check=`{check.UniqueData}`");
|
||||
return content == check.UniqueData;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@ -60,5 +60,10 @@ namespace BiblioTech.Commands
|
||||
{
|
||||
await context.Followup("Successfully completed the check!");
|
||||
}
|
||||
|
||||
public async Task ToAdminChannel(string msg)
|
||||
{
|
||||
await Program.AdminChecker.SendInAdminChannel(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,11 +12,12 @@ namespace BiblioTech.Options
|
||||
public async Task<string?> Parse(CommandContext context)
|
||||
{
|
||||
var strData = context.Options.SingleOrDefault(o => o.Name == Name);
|
||||
if (strData == null)
|
||||
if (strData == null && IsRequired)
|
||||
{
|
||||
await context.Followup("String option not received.");
|
||||
return null;
|
||||
}
|
||||
if (strData == null) return null;
|
||||
return strData.Value as string;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user