fix tmp link download

closes #894
This commit is contained in:
Kukks 2019-06-25 12:23:10 +02:00
parent a58ecfd35a
commit fc1d781272
2 changed files with 15 additions and 15 deletions

View File

@ -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;
}
}
}

View File

@ -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<StoredFileRepository>()),
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<StaticFileResponseContext> HandleStaticFileResponse()
{
return context =>
{
if (context.Context.Request.Query.ContainsKey("download"))
{
context.Context.Response.Headers["Content-Disposition"] = "attachment";
}
};
}
}
}