Adds debug messages for upload check

This commit is contained in:
ThatBen 2025-04-11 08:32:18 +02:00
parent 9540e97e2d
commit fc9aa0726c
No known key found for this signature in database
GPG Key ID: E020A7DDCD52E1AB
4 changed files with 24 additions and 11 deletions

View File

@ -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));
}
}
}

View File

@ -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
{

View File

@ -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);
}
}
}

View File

@ -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;
}
}