mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-02-14 15:53:30 -07:00
parent
6508455f3a
commit
129df42de4
|
|
@ -124,9 +124,9 @@ internal class ExportContext
|
||||||
var filePath = await _assetDownloader.DownloadAsync(url, cancellationToken);
|
var filePath = await _assetDownloader.DownloadAsync(url, cancellationToken);
|
||||||
var relativeFilePath = Path.GetRelativePath(Request.OutputDirPath, filePath);
|
var relativeFilePath = Path.GetRelativePath(Request.OutputDirPath, filePath);
|
||||||
|
|
||||||
// Prefer relative paths so that the output files can be copied around without breaking references.
|
// Prefer the relative path so that the export package can be copied around without breaking references.
|
||||||
// If the asset directory is outside of the export directory, use an absolute path instead.
|
// However, if the assets directory lies outside of the export directory, use the absolute path instead.
|
||||||
var optimalFilePath =
|
var shouldUseAbsoluteFilePath =
|
||||||
relativeFilePath.StartsWith(
|
relativeFilePath.StartsWith(
|
||||||
".." + Path.DirectorySeparatorChar,
|
".." + Path.DirectorySeparatorChar,
|
||||||
StringComparison.Ordinal
|
StringComparison.Ordinal
|
||||||
|
|
@ -134,15 +134,19 @@ internal class ExportContext
|
||||||
|| relativeFilePath.StartsWith(
|
|| relativeFilePath.StartsWith(
|
||||||
".." + Path.AltDirectorySeparatorChar,
|
".." + Path.AltDirectorySeparatorChar,
|
||||||
StringComparison.Ordinal
|
StringComparison.Ordinal
|
||||||
)
|
);
|
||||||
? filePath
|
|
||||||
: relativeFilePath;
|
var optimalFilePath = shouldUseAbsoluteFilePath ? filePath : relativeFilePath;
|
||||||
|
|
||||||
// For HTML, the path needs to be properly formatted
|
// For HTML, the path needs to be properly formatted
|
||||||
if (Request.Format is ExportFormat.HtmlDark or ExportFormat.HtmlLight)
|
if (Request.Format is ExportFormat.HtmlDark or ExportFormat.HtmlLight)
|
||||||
{
|
{
|
||||||
// Create a 'file:///' URI and then strip the 'file:///' prefix to allow for relative paths
|
// Format the path into a valid file URI
|
||||||
return new Uri(new Uri("file:///"), optimalFilePath).ToString()[8..];
|
var href = new Uri(new Uri("file:///"), optimalFilePath).ToString();
|
||||||
|
|
||||||
|
// File schema does not support relative paths, so strip it if that's the case
|
||||||
|
// https://github.com/Tyrrrz/DiscordChatExporter/issues/1155
|
||||||
|
return shouldUseAbsoluteFilePath ? href : href[8..];
|
||||||
}
|
}
|
||||||
|
|
||||||
return optimalFilePath;
|
return optimalFilePath;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue