Skip to content

Commit cf2e622

Browse files
committed
feat(mod): add MuMod config and channel endpoints
1 parent e30abb1 commit cf2e622

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace MaiChartManager.Controllers.Mod;
4+
5+
public record MuModConfigDto(string Channel, string CachePath);
6+
public record SetChannelDto(string Channel);
7+
public record EnsureCacheResultDto(bool Success, string? Version, string? Error);
8+
9+
[ApiController]
10+
[Route("MaiChartManagerServlet/[action]Api")]
11+
public class MuModController(MuModService muModService) : ControllerBase
12+
{
13+
[HttpGet]
14+
public MuModConfigDto GetMuModConfig()
15+
{
16+
var config = muModService.ReadConfig();
17+
return new MuModConfigDto(config.Channel, config.CachePath);
18+
}
19+
20+
[HttpPut]
21+
public async Task<EnsureCacheResultDto> SetMuModChannelAndEnsureCache([FromBody] SetChannelDto req)
22+
{
23+
if (req.Channel != "slow" && req.Channel != "fast")
24+
{
25+
throw new ArgumentException("Channel must be 'slow' or 'fast'", nameof(req));
26+
}
27+
28+
try
29+
{
30+
muModService.WriteChannel(req.Channel);
31+
var result = await muModService.EnsureCache(CancellationToken.None);
32+
return new EnsureCacheResultDto(result.Success, result.Version, result.Error);
33+
}
34+
catch (Exception e)
35+
{
36+
return new EnsureCacheResultDto(false, null, e.Message);
37+
}
38+
}
39+
40+
[HttpPost]
41+
public async Task<EnsureCacheResultDto> EnsureMuModCache()
42+
{
43+
try
44+
{
45+
var result = await muModService.EnsureCache(CancellationToken.None);
46+
return new EnsureCacheResultDto(result.Success, result.Version, result.Error);
47+
}
48+
catch (Exception e)
49+
{
50+
return new EnsureCacheResultDto(false, null, e.Message);
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)