void.cat/VoidCat/Controllers/InfoController.cs

65 lines
2.4 KiB
C#
Raw Permalink 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;
private readonly IEnumerable<string?> _fileStores;
2022-09-08 12:38:32 +00:00
private readonly IEnumerable<string> _oAuthProviders;
2022-03-11 15:59:08 +00:00
2022-06-14 10:46:31 +00:00
public InfoController(IStatsReporter statsReporter, IFileMetadataStore fileMetadata, VoidSettings settings,
2022-09-08 12:38:32 +00:00
ITimeSeriesStatsReporter stats, IEnumerable<IFileStore> fileStores, IEnumerable<IOAuthProvider> oAuthProviders)
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;
_fileStores = fileStores.Select(a => a.Key);
2022-09-08 12:38:32 +00:00
_oAuthProviders = oAuthProviders.Select(a => a.Id);
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
2022-08-28 12:15:50 +00:00
return new()
{
Bandwidth = bw,
TotalBytes = storeStats.Size,
Count = storeStats.Files,
BuildInfo = BuildInfo.GetBuildInfo(),
CaptchaSiteKey = _settings.CaptchaSettings?.SiteKey,
TimeSeriesMetrics = await _timeSeriesStats.GetBandwidth(DateTime.UtcNow.AddDays(-30), DateTime.UtcNow),
FileStores = _fileStores,
2022-09-08 12:38:32 +00:00
UploadSegmentSize = _settings.UploadSegmentSize,
OAuthProviders = _oAuthProviders
2022-08-28 12:15:50 +00:00
};
2022-03-11 15:59:08 +00:00
}
2022-08-28 12:15:50 +00:00
public sealed class GlobalInfo
{
public Bandwidth Bandwidth { get; init; }
public ulong TotalBytes { get; init; }
public long Count { get; init; }
public BuildInfo BuildInfo { get; init; }
public string? CaptchaSiteKey { get; init; }
public IEnumerable<BandwidthPoint> TimeSeriesMetrics { get; init; }
public IEnumerable<string?> FileStores { get; init; }
public ulong? UploadSegmentSize { get; init; }
2022-09-08 12:38:32 +00:00
public IEnumerable<string> OAuthProviders { get; init; }
2022-08-28 12:15:50 +00:00
}
}