Does this work?

This commit is contained in:
defnotken
2026-01-15 13:03:49 -06:00
parent e8c56bb3bc
commit 134268c422
3 changed files with 55 additions and 2 deletions

View File

@@ -10,7 +10,8 @@ public class CDNDownloadsService
Disabled,
Unauthorized,
NotFound,
Success
Success,
Downloading
}
public readonly record struct Result(ResultStatus Status, FileInfo? File);
@@ -53,4 +54,32 @@ public class CDNDownloadsService
return new Result(ResultStatus.Success, fileInfo);
}
public Result GetDownloadWithCacheCheck(string hash, long expiresUnixSeconds, string signature)
{
if (!_cdnDownloadUrlService.DirectDownloadsEnabled)
{
return new Result(ResultStatus.Disabled, null);
}
if (string.IsNullOrEmpty(signature) || string.IsNullOrEmpty(hash))
{
return new Result(ResultStatus.Unauthorized, null);
}
hash = hash.ToUpperInvariant();
if (!_cdnDownloadUrlService.TryValidateSignature(hash, expiresUnixSeconds, signature))
{
return new Result(ResultStatus.Unauthorized, null);
}
var fileInfo = _cachedFileProvider.TryGetLocalFileInfo(hash);
if (fileInfo == null)
{
return new Result(ResultStatus.Downloading, null);
}
return new Result(ResultStatus.Success, fileInfo);
}
}