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
This commit is contained in:
Umar Bolatov 2021-03-01 05:43:57 -08:00 committed by GitHub
parent e8df010449
commit c9cfe5cc6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -37,7 +37,9 @@ namespace BTCPayServer.Storage.Services.Providers.FileSystemStorage
public override async Task<string> 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);
}

View File

@ -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())
</a>
</div>
</li>
<li class="list-group-item ">
<div class="row px-0 mx-0">
<span class="col-sm-12 col-md-2">Direct Url </span>
<span class="col-sm-12 col-md-2">Direct Url: </span>
<a class="col-sm-12 col-md-10 text-right" href="@Model.DirectFileUrl" target="_blank">@Model.DirectFileUrl</a>
</div>
</li>