fix file timezone and isDownload for local files temp urls (#837)

closes #834
This commit is contained in:
Andrew Camilleri
2019-05-15 13:02:03 +00:00
committed by Nicolas Dorier
parent 7aa6d1a8d7
commit 461462eafc
5 changed files with 19 additions and 6 deletions

View File

@@ -14,6 +14,7 @@ using BTCPayServer.Storage.Services.Providers.GoogleCloudStorage;
using BTCPayServer.Storage.Services.Providers.GoogleCloudStorage.Configuration;
using BTCPayServer.Storage.Services.Providers.Models;
using BTCPayServer.Storage.ViewModels;
using BTCPayServer.Views;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
@@ -96,7 +97,7 @@ namespace BTCPayServer.Controllers
return NotFound();
}
var expiry = DateTimeOffset.Now;
var expiry = DateTimeOffset.UtcNow;
switch (viewModel.TimeType)
{
case CreateTemporaryFileUrlViewModel.TmpFileTimeType.Seconds:
@@ -122,7 +123,7 @@ namespace BTCPayServer.Controllers
StatusMessage = new StatusMessageModel()
{
Html =
$"Generated Temporary Url for file {file.FileName} which expires at {expiry:G}. <a href='{url}' target='_blank'>{url}</a>"
$"Generated Temporary Url for file {file.FileName} which expires at {expiry.ToBrowserDate()}. <a href='{url}' target='_blank'>{url}</a>"
}.ToString(),
fileId,
});

View File

@@ -57,10 +57,10 @@ namespace BTCPayServer.Storage.Services.Providers.FileSystemStorage
StringComparison.InvariantCultureIgnoreCase);
}
public override Task<string> GetTemporaryFileUrl(StoredFile storedFile, StorageSettings configuration, DateTimeOffset expiry, bool isDownload,
public override async Task<string> GetTemporaryFileUrl(StoredFile storedFile, StorageSettings configuration, DateTimeOffset expiry, bool isDownload,
BlobUrlAccess access = BlobUrlAccess.Read)
{
return GetFileUrl(storedFile, configuration);
return $"{(await GetFileUrl(storedFile, configuration))}{(isDownload ? "?download" : string.Empty)}";
}
}
}

View File

@@ -43,7 +43,14 @@ namespace BTCPayServer.Storage
{
ServeUnknownFileTypes = true,
RequestPath = new PathString($"/{FileSystemFileProviderService.LocalStorageDirectoryName}"),
FileProvider = new PhysicalFileProvider(dirInfo.FullName)
FileProvider = new PhysicalFileProvider(dirInfo.FullName),
OnPrepareResponse = context =>
{
if (context.Context.Request.Query.ContainsKey("download"))
{
context.Context.Response.Headers["Content-Disposition"] = "attachment";
}
}
});
}
}

View File

@@ -22,7 +22,7 @@
{
<tr>
<td>@file.FileName</td>
<td>@file.Timestamp.ToString("g")</td>
<td >@file.Timestamp.ToBrowserDate2()</td>
<td>@file.ApplicationUser.UserName</td>
<td>
<a asp-action="Files" asp-route-fileId="@file.Id">Get Link</a>

View File

@@ -31,6 +31,11 @@ namespace BTCPayServer.Views
return new HtmlString($"<span class='localizeDate'>{hello}</span>");
}
public static HtmlString ToBrowserDate2(this DateTime date)
{
var hello = date.ToString("o", CultureInfo.InvariantCulture);
return new HtmlString($"<span class='localizeDate'>{hello}</span>");
}
public static string ToTimeAgo(this DateTimeOffset date)
{
var formatted = (DateTimeOffset.UtcNow - date).TimeString() + " ago";