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;
|
2022-04-03 14:47:54 +08:00
|
|
|
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]")]
|
2022-06-09 15:40:08 +08:00
|
|
|
public sealed class ConfigController : ControllerBase
|
2022-04-03 13:34:55 +08:00
|
|
|
{
|
|
|
|
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);
|
2022-07-08 21:13:00 +08:00
|
|
|
this.recorder.SaveConfig();
|
2022-04-03 13:34:55 +08:00
|
|
|
return this.mapper.Map<GlobalConfigDto>(this.recorder.Config.Global);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|