BililiveRecorder/BililiveRecorder.Web/Api/ConfigController.cs

50 lines
1.6 KiB
C#
Raw Normal View History

2022-04-03 13:34:55 +08:00
using System;
using AutoMapper;
using BililiveRecorder.Core;
2022-04-03 20:43:38 +08:00
using BililiveRecorder.Core.Config.V3;
2022-04-03 13:34:55 +08:00
using BililiveRecorder.Web.Models;
using BililiveRecorder.Web.Models.Rest;
2022-04-03 13:34:55 +08:00
using Microsoft.AspNetCore.Mvc;
namespace BililiveRecorder.Web.Api
{
[ApiController, Route("api/[controller]", Name = "[controller] [action]")]
public class ConfigController : ControllerBase
{
private readonly IMapper mapper;
private readonly IRecorder recorder;
public ConfigController(IMapper mapper, IRecorder recorder)
{
this.mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
this.recorder = recorder ?? throw new ArgumentNullException(nameof(recorder));
}
/// <summary>
/// 获取软件默认设置
/// </summary>
/// <returns></returns>
[HttpGet("default")]
public ActionResult<DefaultConfig> GetDefaultConfig() => DefaultConfig.Instance;
/// <summary>
/// 获取全局设置
/// </summary>
/// <returns></returns>
[HttpGet("global")]
public ActionResult<GlobalConfigDto> GetGlobalConfig() => this.mapper.Map<GlobalConfigDto>(this.recorder.Config.Global);
/// <summary>
/// 设置全局设置
/// </summary>
/// <param name="config"></param>
/// <returns></returns>
[HttpPost("global")]
public ActionResult<GlobalConfigDto> SetGlobalConfig([FromBody] SetGlobalConfig config)
{
config.ApplyTo(this.recorder.Config.Global);
return this.mapper.Map<GlobalConfigDto>(this.recorder.Config.Global);
}
}
}