Regenerates unique data for new checks

This commit is contained in:
ThatBen 2025-04-23 09:07:19 +02:00
parent c630d4c81e
commit 9446671b18
No known key found for this signature in database
GPG Key ID: 62C543548433D43E

View File

@ -37,7 +37,7 @@ namespace BiblioTech.CodexChecking
public async Task StartDownloadCheck(ICheckResponseHandler handler, ulong userId)
{
var check = repo.GetOrCreate(userId).DownloadCheck;
if (string.IsNullOrEmpty(check.UniqueData))
if (IsUniqueDataStale(check))
{
check.UniqueData = GenerateUniqueData();
repo.SaveChanges();
@ -69,7 +69,7 @@ namespace BiblioTech.CodexChecking
public async Task StartUploadCheck(ICheckResponseHandler handler, ulong userId)
{
var check = repo.GetOrCreate(userId).UploadCheck;
if (string.IsNullOrEmpty(check.UniqueData))
if (IsUniqueDataStale(check))
{
check.UniqueData = GenerateUniqueData();
repo.SaveChanges();
@ -111,6 +111,15 @@ namespace BiblioTech.CodexChecking
return $"{RandomBusyMessage.Get().Substring(5)}{RandomUtils.GenerateRandomString(12)}";
}
private bool IsUniqueDataStale(TransferCheck check)
{
var expiry = DateTime.UtcNow - TimeSpan.FromMinutes(10.0);
return
string.IsNullOrEmpty(check.UniqueData) ||
check.CompletedUtc < expiry;
}
private string UploadData(string uniqueData)
{
var filePath = Path.Combine(config.ChecksDataPath, Guid.NewGuid().ToString());