43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
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 });
|
|
}
|
|
}
|