From fc1d78127290095182701dd76311d10828bb9813 Mon Sep 17 00:00:00 2001 From: Kukks Date: Tue, 25 Jun 2019 12:23:10 +0200 Subject: [PATCH] fix tmp link download closes #894 --- .../FileSystemFileProviderService.cs | 2 +- BTCPayServer/Storage/StorageExtensions.cs | 28 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/BTCPayServer/Storage/Services/Providers/FileSystemStorage/FileSystemFileProviderService.cs b/BTCPayServer/Storage/Services/Providers/FileSystemStorage/FileSystemFileProviderService.cs index b91670869..fef268530 100644 --- a/BTCPayServer/Storage/Services/Providers/FileSystemStorage/FileSystemFileProviderService.cs +++ b/BTCPayServer/Storage/Services/Providers/FileSystemStorage/FileSystemFileProviderService.cs @@ -72,7 +72,7 @@ namespace BTCPayServer.Storage.Services.Providers.FileSystemStorage await File.WriteAllTextAsync(Path.Combine(GetTempStorageDir(_options), name), JsonConvert.SerializeObject(localFileDescriptor)); - return new Uri(baseUri,$"{LocalStorageDirectoryName}tmp/{name}" ).AbsoluteUri; + return new Uri(baseUri,$"{LocalStorageDirectoryName}tmp/{name}{(isDownload ? "?download" : string.Empty)}").AbsoluteUri; } } } diff --git a/BTCPayServer/Storage/StorageExtensions.cs b/BTCPayServer/Storage/StorageExtensions.cs index b64c66799..c5f2e487a 100644 --- a/BTCPayServer/Storage/StorageExtensions.cs +++ b/BTCPayServer/Storage/StorageExtensions.cs @@ -7,6 +7,7 @@ using BTCPayServer.Storage.Services.Providers.AzureBlobStorage; using BTCPayServer.Storage.Services.Providers.FileSystemStorage; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.StaticFiles; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Logging; @@ -57,13 +58,7 @@ namespace BTCPayServer.Storage ServeUnknownFileTypes = true, RequestPath = new PathString($"/{FileSystemFileProviderService.LocalStorageDirectoryName}"), FileProvider = new PhysicalFileProvider(dirInfo.FullName), - OnPrepareResponse = context => - { - if (context.Context.Request.Query.ContainsKey("download")) - { - context.Context.Response.Headers["Content-Disposition"] = "attachment"; - } - } + OnPrepareResponse = HandleStaticFileResponse() }); builder.UseStaticFiles(new StaticFileOptions() { @@ -71,13 +66,7 @@ namespace BTCPayServer.Storage RequestPath = new PathString($"/{FileSystemFileProviderService.LocalStorageDirectoryName}tmp"), FileProvider = new TemporaryLocalFileProvider(tmpdirInfo, dirInfo, builder.ApplicationServices.GetService()), - OnPrepareResponse = context => - { - if (context.Context.Request.Query.ContainsKey("download")) - { - context.Context.Response.Headers["Content-Disposition"] = "attachment"; - } - } + OnPrepareResponse = HandleStaticFileResponse() }); } catch (Exception e) @@ -85,5 +74,16 @@ namespace BTCPayServer.Storage Logs.Utils.LogError(e, $"Could not initialize the Local File Storage system(uploading and storing files locally)"); } } + + private static Action HandleStaticFileResponse() + { + return context => + { + if (context.Context.Request.Query.ContainsKey("download")) + { + context.Context.Response.Headers["Content-Disposition"] = "attachment"; + } + }; + } } }