65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
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);
|
||
}
|
||
}
|
||
}
|
||
|