2022-06-09 15:40:08 +08:00
|
|
|
using System;
|
|
|
|
using AutoMapper;
|
|
|
|
using BililiveRecorder.Core.Config.V3;
|
|
|
|
using BililiveRecorder.Core.Templating;
|
|
|
|
using BililiveRecorder.Web.Models.Rest;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
namespace BililiveRecorder.Web.Api
|
|
|
|
{
|
|
|
|
[ApiController, Route("api/[controller]", Name = "[controller] [action]")]
|
|
|
|
public sealed class MiscController : ControllerBase
|
|
|
|
{
|
|
|
|
private readonly IMapper mapper;
|
|
|
|
|
|
|
|
public MiscController(IMapper mapper)
|
|
|
|
{
|
|
|
|
this.mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 根据传入参数生成录播文件名
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("generateFileName")]
|
2022-06-28 16:10:06 +08:00
|
|
|
public ActionResult<FileNameTemplateOutput> GenerateFileName([FromBody] GenerateFileNameInput input)
|
2022-06-09 15:40:08 +08:00
|
|
|
{
|
|
|
|
var config = new GlobalConfig()
|
|
|
|
{
|
|
|
|
WorkDirectory = "/",
|
|
|
|
FileNameRecordTemplate = input.Template
|
|
|
|
};
|
2022-06-28 16:10:06 +08:00
|
|
|
var generator = new FileNameGenerator(config, null);
|
2022-06-09 15:40:08 +08:00
|
|
|
|
|
|
|
var context = this.mapper.Map<FileNameTemplateContext>(input.Context);
|
|
|
|
|
2022-06-28 16:10:06 +08:00
|
|
|
var output = generator.CreateFilePath(context);
|
|
|
|
return output;
|
2022-06-09 15:40:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|