void.cat/VoidCat/Controllers/InfoController.cs

42 lines
1.4 KiB
C#
Raw Normal View History

2022-03-11 15:59:08 +00:00
using Microsoft.AspNetCore.Mvc;
using VoidCat.Model;
using VoidCat.Services.Abstractions;
namespace VoidCat.Controllers;
[Route("info")]
public class InfoController : Controller
{
private readonly IStatsReporter _statsReporter;
2022-06-06 21:51:25 +00:00
private readonly IFileMetadataStore _fileMetadata;
2022-03-11 15:59:08 +00:00
private readonly VoidSettings _settings;
2022-06-14 10:46:31 +00:00
private readonly ITimeSeriesStatsReporter _timeSeriesStats;
2022-03-11 15:59:08 +00:00
2022-06-14 10:46:31 +00:00
public InfoController(IStatsReporter statsReporter, IFileMetadataStore fileMetadata, VoidSettings settings,
ITimeSeriesStatsReporter stats)
2022-03-11 15:59:08 +00:00
{
_statsReporter = statsReporter;
2022-06-06 21:51:25 +00:00
_fileMetadata = fileMetadata;
2022-03-11 15:59:08 +00:00
_settings = settings;
2022-06-14 10:46:31 +00:00
_timeSeriesStats = stats;
2022-03-11 15:59:08 +00:00
}
/// <summary>
/// Return system info
/// </summary>
/// <returns></returns>
[HttpGet]
[ResponseCache(Location = ResponseCacheLocation.Any, Duration = 60)]
public async Task<GlobalInfo> GetGlobalStats()
{
var bw = await _statsReporter.GetBandwidth();
2022-06-06 21:51:25 +00:00
var storeStats = await _fileMetadata.Stats();
2022-06-14 10:46:31 +00:00
return new(bw, storeStats.Size, storeStats.Files, BuildInfo.GetBuildInfo(),
_settings.CaptchaSettings?.SiteKey,
await _timeSeriesStats.GetBandwidth(DateTime.UtcNow.AddDays(-30), DateTime.UtcNow));
2022-03-11 15:59:08 +00:00
}
2022-06-06 21:51:25 +00:00
public sealed record GlobalInfo(Bandwidth Bandwidth, ulong TotalBytes, long Count, BuildInfo BuildInfo,
2022-06-14 10:46:31 +00:00
string? CaptchaSiteKey, IEnumerable<BandwidthPoint> TimeSeriesMetrics);
2022-03-11 15:59:08 +00:00
}