From c9cfe5cc6edeb95ad8d5fc25c5929072eb185692 Mon Sep 17 00:00:00 2001 From: Umar Bolatov Date: Mon, 1 Mar 2021 05:43:57 -0800 Subject: [PATCH] Fix direct URL for local storage with custom root path (#2318) * Fix direct URL for local storage with custom root path * Remove "Context.Request.PathBase" when generating file URL display string --- .../FileSystemStorage/FileSystemFileProviderService.cs | 4 +++- BTCPayServer/Views/Server/Files.cshtml | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/BTCPayServer/Storage/Services/Providers/FileSystemStorage/FileSystemFileProviderService.cs b/BTCPayServer/Storage/Services/Providers/FileSystemStorage/FileSystemFileProviderService.cs index ece998eec..20fb55dd7 100644 --- a/BTCPayServer/Storage/Services/Providers/FileSystemStorage/FileSystemFileProviderService.cs +++ b/BTCPayServer/Storage/Services/Providers/FileSystemStorage/FileSystemFileProviderService.cs @@ -37,7 +37,9 @@ namespace BTCPayServer.Storage.Services.Providers.FileSystemStorage public override async Task GetFileUrl(Uri baseUri, StoredFile storedFile, StorageSettings configuration) { var baseResult = await base.GetFileUrl(baseUri, storedFile, configuration); - var url = new Uri(baseUri, LocalStorageDirectoryName); + // Set the relative URL to the directory name if the root path is default, otherwise add root path before the directory name + var relativeUrl = baseUri.AbsolutePath == "/" ? LocalStorageDirectoryName : $"{baseUri.AbsolutePath}/{LocalStorageDirectoryName}"; + var url = new Uri(baseUri, relativeUrl); return baseResult.Replace(new DirectoryInfo(_datadirs.Value.StorageDir).FullName, url.AbsoluteUri, StringComparison.InvariantCultureIgnoreCase); } diff --git a/BTCPayServer/Views/Server/Files.cshtml b/BTCPayServer/Views/Server/Files.cshtml index f304aa7f9..71f6fac30 100644 --- a/BTCPayServer/Views/Server/Files.cshtml +++ b/BTCPayServer/Views/Server/Files.cshtml @@ -64,13 +64,13 @@ else @Url.Action("GetFile", "Storage", new { fileId = Model.SelectedFileId - }, Context.Request.Scheme, Context.Request.Host.ToString(), Context.Request.PathBase.ToString()) + }, Context.Request.Scheme, Context.Request.Host.ToString())
  • - Direct Url + Direct Url: @Model.DirectFileUrl