Skip to content

Commit

Permalink
Localtest: Sort files in directoryBrowser by LastModified (#9572)
Browse files Browse the repository at this point in the history
Sorting by guid does not make any sense.

Co-authored-by: Ivar <[email protected]>
  • Loading branch information
ivarne and ivarne authored Jan 13, 2023
1 parent e431fbd commit 03e4e24
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/Helpers/SortedHtmlDirectoryFormatter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Text.Encodings.Web;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.FileProviders;

namespace LocalTest.Helpers;

public class SortedHtmlDirectoryFormatter : HtmlDirectoryFormatter
{
public SortedHtmlDirectoryFormatter() : base(HtmlEncoder.Default) { }

public override Task GenerateContentAsync(HttpContext context, IEnumerable<IFileInfo> contents)
{
var sorted = contents.OrderByDescending(f => f.LastModified);
return base.GenerateContentAsync(context, sorted);
}
}
4 changes: 3 additions & 1 deletion src/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using AltinnCore.Authentication.JwtCookie;
using LocalTest.Clients.CdnAltinnOrgs;
using LocalTest.Configuration;
using LocalTest.Helpers;
using LocalTest.Services.Authentication.Implementation;
using LocalTest.Services.Authentication.Interface;
using LocalTest.Services.Authorization.Implementation;
Expand Down Expand Up @@ -208,7 +209,8 @@ public void Configure(
app.UseDirectoryBrowser(new DirectoryBrowserOptions
{
FileProvider = new PhysicalFileProvider(localPlatformSettings.Value.LocalTestingStorageBasePath),
RequestPath = "/LocalPlatformStorage"
RequestPath = "/LocalPlatformStorage",
Formatter = new SortedHtmlDirectoryFormatter(),
});
app.UseStaticFiles();

Expand Down

0 comments on commit 03e4e24

Please sign in to comment.