
// 








namespace SafeCampus.Web.Core;

/// <summary>
/// 文件管理控制器
/// </summary>
[ApiDescriptionSettings(Tag = "文件管理")]
[Route("sys/dev/[controller]")]
public class FileController : BaseController
{
    private readonly IFileService _fileService;

    public FileController(IFileService fileService)
    {
        _fileService = fileService;
    }

    /// <summary>
    /// 文件查询分页
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet("page")]
    public async Task<dynamic> Page([FromQuery] FilePageInput input)
    {
        return await _fileService.Page(input);
    }

    /// <summary>
    /// 上传本地文件
    /// </summary>
    /// <param name="file"></param>
    /// <returns></returns>
    [HttpPost("uploadLocal")]
    [DisplayName("上传本地文件")]
    [DisableRequestSizeLimit]
    public async Task<long> UploadLocal([FromForm] IFormFile file)
    {
        return await _fileService.UploadFile(SysDictConst.FILE_ENGINE_LOCAL, file);
    }

    /// <summary>
    /// 上传MINIO文件
    /// </summary>
    /// <param name="file"></param>
    /// <returns></returns>
    [HttpPost("uploadMinio")]
    [DisplayName("上传MINIO文件")]
    [DisableRequestSizeLimit]
    public async Task<long> UploadMinio([FromForm] IFormFile file)
    {
        return await _fileService.UploadFile(SysDictConst.FILE_ENGINE_MINIO, file);
    }

    /// <summary>
    /// 删除文件
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("delete")]
    [DisplayName("删除文件")]
    public async Task Delete([FromBody] BaseIdListInput input)
    {
        await _fileService.Delete(input);
    }

    /// <summary>
    /// 下载文件
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet("download")]
    [DisplayName("下载文件")]
    public async Task<IActionResult> DownLoad([FromQuery] BaseIdInput input)
    {
        return await _fileService.Download(input);
    }
}
