pull/1046/head
Tyrrrz 2 years ago
parent 768fb88c8c
commit c69211797f

@ -48,9 +48,9 @@ public static class ExportWrapper
var fileName = channelId.ToString() + '.' + format.GetFileExtension();
var filePath = Path.Combine(DirPath, fileName);
// Lock separately for each channel and format
using (await Locker.LockAsync(filePath))
{
using var _ = await Locker.LockAsync(filePath);
using var console = new FakeConsole();
// Perform the export only if it hasn't been done before
if (!File.Exists(filePath))
{
@ -60,12 +60,11 @@ public static class ExportWrapper
ChannelIds = new[] { channelId },
ExportFormat = format,
OutputPath = filePath
}.ExecuteAsync(new FakeConsole());
}.ExecuteAsync(console);
}
return await File.ReadAllTextAsync(filePath);
}
}
public static async ValueTask<IHtmlDocument> ExportAsHtmlAsync(Snowflake channelId) => Html.Parse(
await ExportAsync(channelId, ExportFormat.HtmlDark)

@ -38,8 +38,8 @@ internal partial class ExportAssetDownloader
var fileName = GetFileNameFromUrl(url);
var filePath = Path.Combine(_workingDirPath, fileName);
using (await Locker.LockAsync(filePath, cancellationToken))
{
using var _ = await Locker.LockAsync(filePath, cancellationToken);
if (_pathCache.TryGetValue(url, out var cachedFilePath))
return cachedFilePath;
@ -83,7 +83,6 @@ internal partial class ExportAssetDownloader
return _pathCache[url] = filePath;
}
}
}
internal partial class ExportAssetDownloader
{

@ -89,27 +89,17 @@ internal class ExportContext
public Role? TryGetRole(Snowflake id) => _roles.GetValueOrDefault(id);
public Color? TryGetUserColor(Snowflake id)
{
var memberRoles = GetUserRoles(id);
return memberRoles?
.Where(r => r.Color is not null)
.Select(r => r.Color)
.FirstOrDefault();
}
public IReadOnlyList<Role> GetUserRoles(Snowflake id)
{
var member = TryGetMember(id);
return member?
public IReadOnlyList<Role> GetUserRoles(Snowflake id) => TryGetMember(id)?
.RoleIds
.Select(TryGetRole)
.WhereNotNull()
.OrderByDescending(r => r.Position)
.ToArray() ?? Array.Empty<Role>();
}
public Color? TryGetUserColor(Snowflake id) => GetUserRoles(id)
.Where(r => r.Color is not null)
.Select(r => r.Color)
.FirstOrDefault();
public async ValueTask<string> ResolveAssetUrlAsync(string url, CancellationToken cancellationToken = default)
{
@ -122,7 +112,7 @@ internal class ExportContext
var relativeFilePath = Path.GetRelativePath(Request.OutputDirPath, filePath);
// Prefer relative paths so that the output files can be copied around without breaking references.
// If the assets path is outside of the export directory, use an absolute path instead.
// If the asset directory is outside of the export directory, use an absolute path instead.
var optimalFilePath =
relativeFilePath.StartsWith(".." + Path.DirectorySeparatorChar, StringComparison.Ordinal) ||
relativeFilePath.StartsWith(".." + Path.AltDirectorySeparatorChar, StringComparison.Ordinal)

Loading…
Cancel
Save