mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-05-29 12:11:58 +00:00
Clean up last commit
This commit is contained in:
@@ -15,11 +15,12 @@ namespace DiscordChatExporter.Core.Exporting;
|
|||||||
|
|
||||||
internal partial class ExportAssetDownloader
|
internal partial class ExportAssetDownloader
|
||||||
{
|
{
|
||||||
private static readonly AsyncKeyedLocker<string> _locker = new(o =>
|
private static readonly AsyncKeyedLocker<string> Locker = new(o =>
|
||||||
{
|
{
|
||||||
o.PoolSize = 20;
|
o.PoolSize = 20;
|
||||||
o.PoolInitialFill = 1;
|
o.PoolInitialFill = 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
private readonly string _workingDirPath;
|
private readonly string _workingDirPath;
|
||||||
private readonly bool _reuse;
|
private readonly bool _reuse;
|
||||||
|
|
||||||
@@ -37,14 +38,15 @@ internal partial class ExportAssetDownloader
|
|||||||
var fileName = GetFileNameFromUrl(url);
|
var fileName = GetFileNameFromUrl(url);
|
||||||
var filePath = Path.Combine(_workingDirPath, fileName);
|
var filePath = Path.Combine(_workingDirPath, fileName);
|
||||||
|
|
||||||
using (await _locker.LockAsync(filePath, cancellationToken).ConfigureAwait(false))
|
using (await Locker.LockAsync(filePath, cancellationToken))
|
||||||
{
|
{
|
||||||
if (_pathCache.TryGetValue(url, out var cachedFilePath))
|
if (_pathCache.TryGetValue(url, out var cachedFilePath))
|
||||||
return cachedFilePath;
|
return cachedFilePath;
|
||||||
|
|
||||||
// Reuse existing files if we're allowed to
|
// Reuse existing files if we're allowed to
|
||||||
if (!_reuse || !File.Exists(filePath))
|
if (_reuse && File.Exists(filePath))
|
||||||
{
|
return _pathCache[url] = filePath;
|
||||||
|
|
||||||
Directory.CreateDirectory(_workingDirPath);
|
Directory.CreateDirectory(_workingDirPath);
|
||||||
|
|
||||||
await Http.ResiliencePolicy.ExecuteAsync(async () =>
|
await Http.ResiliencePolicy.ExecuteAsync(async () =>
|
||||||
@@ -78,7 +80,6 @@ internal partial class ExportAssetDownloader
|
|||||||
// ignore exceptions thrown here.
|
// ignore exceptions thrown here.
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return _pathCache[url] = filePath;
|
return _pathCache[url] = filePath;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user