Does this work?
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user