Add /api/info endpoint for build time, title.js, UI tweaks
This commit is contained in:
1 parent
bdd3173e5f
commit
6556d62f17
10 files changed
+77
-20
No files matched your search
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
|
||||
namespace Gott.Endpoints;
|
||||
|
||||
public static class InfoEndpoint
|
||||
{
|
||||
public static void MapInfoEndpoint(this IEndpointRouteBuilder app)
|
||||
{
|
||||
app.MapGet("/api/info", HandleInfo);
|
||||
}
|
||||
|
||||
private static IResult HandleInfo()
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
var location = assembly.Location;
|
||||
|
||||
long buildTime = 0;
|
||||
|
||||
if (!string.IsNullOrEmpty(location) && File.Exists(location))
|
||||
{
|
||||
var lastWrite = File.GetLastWriteTimeUtc(location);
|
||||
buildTime = new DateTimeOffset(lastWrite).ToUnixTimeSeconds();
|
||||
}
|
||||
else
|
||||
{
|
||||
var dir = AppContext.BaseDirectory;
|
||||
var exePath = Path.Combine(dir, "gott");
|
||||
if (File.Exists(exePath))
|
||||
{
|
||||
var lastWrite = File.GetLastWriteTimeUtc(exePath);
|
||||
buildTime = new DateTimeOffset(lastWrite).ToUnixTimeSeconds();
|
||||
}
|
||||
}
|
||||
|
||||
return Results.Json(new { buildTime });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user