|
|
@ -92,13 +92,19 @@ internal class ExportContext
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var filePath = await _assetDownloader.DownloadAsync(url, cancellationToken);
|
|
|
|
var absoluteFilePath = await _assetDownloader.DownloadAsync(url, cancellationToken);
|
|
|
|
|
|
|
|
|
|
|
|
// We want relative path so that the output files can be copied around without breaking.
|
|
|
|
// We want relative path so that the output files can be copied around without breaking.
|
|
|
|
// Base directory path may be null if the file is stored at the root or relative to working directory.
|
|
|
|
// Base directory path may be null if the file is stored at the root or relative to working directory.
|
|
|
|
var relativeFilePath = !string.IsNullOrWhiteSpace(Request.OutputBaseDirPath)
|
|
|
|
var relativeFilePath = !string.IsNullOrWhiteSpace(Request.OutputBaseDirPath)
|
|
|
|
? Path.GetRelativePath(Request.OutputBaseDirPath, filePath)
|
|
|
|
? Path.GetRelativePath(Request.OutputBaseDirPath, absoluteFilePath)
|
|
|
|
: filePath;
|
|
|
|
: absoluteFilePath;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If the assets path is outside of the export directory, fall back to absolute path
|
|
|
|
|
|
|
|
var filePath = relativeFilePath.StartsWith("..")
|
|
|
|
|
|
|
|
? absoluteFilePath
|
|
|
|
|
|
|
|
: relativeFilePath;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// HACK: for HTML, we need to format the URL properly
|
|
|
|
// HACK: for HTML, we need to format the URL properly
|
|
|
|
if (Request.Format is ExportFormat.HtmlDark or ExportFormat.HtmlLight)
|
|
|
|
if (Request.Format is ExportFormat.HtmlDark or ExportFormat.HtmlLight)
|
|
|
@ -106,13 +112,14 @@ internal class ExportContext
|
|
|
|
// Need to escape each path segment while keeping the directory separators intact
|
|
|
|
// Need to escape each path segment while keeping the directory separators intact
|
|
|
|
return string.Join(
|
|
|
|
return string.Join(
|
|
|
|
Path.AltDirectorySeparatorChar,
|
|
|
|
Path.AltDirectorySeparatorChar,
|
|
|
|
relativeFilePath
|
|
|
|
filePath
|
|
|
|
.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)
|
|
|
|
.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)
|
|
|
|
.Select(Uri.EscapeDataString)
|
|
|
|
.Select(Uri.EscapeDataString)
|
|
|
|
|
|
|
|
.Select(x => x.Replace("%3A", ":"))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return relativeFilePath;
|
|
|
|
return filePath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Try to catch only exceptions related to failed HTTP requests
|
|
|
|
// Try to catch only exceptions related to failed HTTP requests
|
|
|
|
// https://github.com/Tyrrrz/DiscordChatExporter/issues/332
|
|
|
|
// https://github.com/Tyrrrz/DiscordChatExporter/issues/332
|
|
|
|