live-forum/server/webapi/LiveForum/LiveForum.WebApi/Controllers/CosController.cs
2026-03-24 11:27:37 +08:00

65 lines
2.0 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using LiveForum.Code.Base;
using LiveForum.IService.Others;
using LiveForum.Model.Dto.Others;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace LiveForum.WebApi.Controllers
{
/// <summary>
/// 腾讯云COS相关接口
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
public class CosController : ControllerBase
{
private readonly ICosService _cosService;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="cosService">COS服务</param>
public CosController(ICosService cosService)
{
_cosService = cosService;
}
/// <summary>
/// 获取COS签名URL
/// </summary>
/// <param name="key">对象键(文件路径)</param>
/// <param name="httpMethod">HTTP请求方法默认PUT</param>
/// <returns></returns>
[HttpGet]
[Authorize]
public async Task<BaseResponse<CosGenerateSignRespDto>> GetCosSign(string key, string httpMethod = "PUT")
{
var request = new CosGenerateSignReq
{
Key = key,
HttpMethod = httpMethod
};
return await _cosService.GenerateSignURL(request);
}
/// <summary>
/// 获取临时密钥
/// </summary>
/// <param name="fileName">文件名</param>
/// <param name="modelName">模型名称文件夹名称images、videos</param>
/// <returns></returns>
[HttpGet]
[Authorize]
public async Task<BaseResponse<CosGenerateTemporaryKeyRespDto>> GetGenerateTemporaryKey(string fileName = "", string modelName = "")
{
var request = new CosGenerateTemporaryKeyReq
{
FileName = fileName,
ModelName = modelName
};
return await _cosService.GenerateTemporaryKey(request);
}
}
}