2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-04-05 17:39:39 -04:00
pulsar/Pulsar/Features/Status/StatusController.cs
Ben Parsons 6f4330ef12 Added Basic File Watched
Started structure of Status Service
Not Yet Tested
2024-04-18 23:45:29 +10:00

30 lines
1.1 KiB
C#

namespace Pulsar.Features.Status;
[ApiController]
[Route("api/status")]
public class StatusController(IOptions<PulsarConfiguration> pulsarOptions, IHubContext<EventsHub, IEventsHub> hub) : ControllerBase
{
[HttpGet]
public async Task<IActionResult> Get()
{
// TODO: put in service
var journalDir = pulsarOptions.Value.JournalDirectory;
var dir = new DirectoryInfo(journalDir);
if (!dir.Exists)
return Problem("Journal directory does not exist.");
var files = dir.GetFiles();
var statusFile = files.FirstOrDefault(f =>
string.Equals(f.Name, "status.json", StringComparison.InvariantCultureIgnoreCase));
if (statusFile == null)
return Problem("Status file not found.");
await using var file = System.IO.File.Open(statusFile.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
var status = await JsonSerializer.DeserializeAsync<Observatory.Framework.Files.Status>(file);
await hub.Clients.All.StatusUpdated(status);
return Ok(status);
}
}