using System; using AutoMapper; using BililiveRecorder.Core; using BililiveRecorder.Core.Config.V3; using BililiveRecorder.Web.Models; using BililiveRecorder.Web.Models.Rest; 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)); } /// /// 获取软件默认设置 /// /// [HttpGet("default")] public ActionResult GetDefaultConfig() => DefaultConfig.Instance; /// /// 获取全局设置 /// /// [HttpGet("global")] public ActionResult GetGlobalConfig() => this.mapper.Map(this.recorder.Config.Global); /// /// 设置全局设置 /// /// /// [HttpPost("global")] public ActionResult SetGlobalConfig([FromBody] SetGlobalConfig config) { config.ApplyTo(this.recorder.Config.Global); return this.mapper.Map(this.recorder.Config.Global); } } }