feat: 新增SDK模块、OSS相关功能并优化Redis与代码扩展
1. 新增API版本枚举SDK项,创建SDK基础控制器 2. 添加IList、string扩展方法,新增时间戳扩展工具 3. 新增OSS配置、STS凭证服务、文件处理相关代码 4. 重构Redis缓存组件,替换StackExchange.Redis为CSRedisCore 5. 修复原有Redis操作方法调用,新增基础控制器快捷返回方法 6. 新增阿里云OSS、短信、VOD相关SDK依赖 7. 配置阿里云OSS相关参数到appsettings
This commit is contained in:
@ -60,4 +60,19 @@ public abstract class BaseController : ControllerBase
|
||||
{
|
||||
return BaseResponse<object>.Fail(ResultCode.GLOBAL_ERROR, message);
|
||||
}
|
||||
|
||||
protected IActionResult ApiResult(bool success, string msg)
|
||||
{
|
||||
return success ? Success() : Fail(msg);
|
||||
}
|
||||
|
||||
protected IActionResult Success()
|
||||
{
|
||||
return Ok(BaseResponse.Success());
|
||||
}
|
||||
|
||||
protected IActionResult Fail(string msg)
|
||||
{
|
||||
return Ok(BaseResponse.Fail(msg));
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using QYZH.InteractiveMagazine.Infrastructure.OSS;
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
using Yitter.IdGenerator;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.WebApi.Controllers.SDK
|
||||
{
|
||||
public class OssController : SDKBaseController
|
||||
{
|
||||
private readonly OssService _ossService;
|
||||
|
||||
public OssController(OssService ossService)
|
||||
{
|
||||
this._ossService = ossService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取StsToken
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet, Route("sts")]
|
||||
public async Task<IActionResult> Credentials()
|
||||
{
|
||||
var data = await _ossService.GetSTSToken();
|
||||
return Ok(BaseResponse<Dictionary<string, string>>.Success(data));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除oss文件
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost, Route("delete")]
|
||||
public async Task<IActionResult> DelObject(string key)
|
||||
{
|
||||
// 查看用户是否有权删除
|
||||
var ok = _ossService.DeleteObject(key);
|
||||
return ApiResult(ok, "删除文件失败");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取上传路径前缀
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet, Route("getUploadPrefix")]
|
||||
public async Task<BaseResponse> GetUploadPrefix()
|
||||
{
|
||||
return BaseResponse<string>.Success($"temp/{YitIdHelper.NextId()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using QYZH.InteractiveMagazine.Models.Enum;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.WebApi.Controllers.SDK
|
||||
{
|
||||
[Route("api/sdk/[controller]")]
|
||||
[ApiExplorerSettings(GroupName = nameof(ApiVersionEnum.SDK))]
|
||||
[AllowAnonymous]
|
||||
public class SDKBaseController : BaseController
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -12,6 +12,7 @@ using QYZH.InteractiveMagazine.Infrastructure.Autofacs;
|
||||
using QYZH.InteractiveMagazine.Infrastructure.Context;
|
||||
using QYZH.InteractiveMagazine.Infrastructure.Extensions;
|
||||
using QYZH.InteractiveMagazine.Infrastructure.Middleware;
|
||||
using QYZH.InteractiveMagazine.Infrastructure.Redis;
|
||||
using QYZH.InteractiveMagazine.Models.Entity;
|
||||
using QYZH.InteractiveMagazine.Models.Enum;
|
||||
using QYZH.InteractiveMagazine.Models.Settings;
|
||||
@ -34,6 +35,8 @@ YitIdHelper.SetIdGenerator(new IdGeneratorOptions() { WorkerId = 1 });
|
||||
// autofac注入 允许使用autofac作为DI容器
|
||||
builder.UseAutofac();
|
||||
|
||||
|
||||
|
||||
builder.InitSqlSugarDb(new IocConfig()
|
||||
{
|
||||
ConfigId = 0,
|
||||
@ -45,7 +48,8 @@ builder.InitSqlSugarDb(new IocConfig()
|
||||
// 消除Error unprotecting the session cookie警告
|
||||
builder.Services.AddDataProtection()
|
||||
.PersistKeysToFileSystem(new DirectoryInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "DataProtection"));
|
||||
|
||||
//redis
|
||||
builder.Services.AddCSRedisCacheExtension(builder.Configuration.GetSection("RedisSettings"));
|
||||
// 配置Serilog
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(builder.Configuration)
|
||||
@ -158,6 +162,7 @@ builder.Services.AddCors(options =>
|
||||
.AllowAnyHeader();
|
||||
});
|
||||
});
|
||||
|
||||
#region 配置数据压缩选项
|
||||
|
||||
// 1.首先配置压缩选项的Options>
|
||||
@ -182,6 +187,7 @@ builder.Services.AddResponseCompression(options =>
|
||||
});
|
||||
|
||||
#endregion
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
{
|
||||
|
||||
@ -10,7 +10,8 @@
|
||||
},
|
||||
"RedisSettings": {
|
||||
"ConnectionString": "192.168.20.150:16379,defaultDatabase=5",
|
||||
"InstanceName": "interactive_magazine"
|
||||
"Sentinels": [],
|
||||
"ExpireSecondRange": [ 3600, 7200 ]
|
||||
},
|
||||
"RabbitMQSettings": {
|
||||
"HostName": "192.168.20.150",
|
||||
@ -44,5 +45,17 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"AliyunOSSConfigs": {
|
||||
"AccessKeyID": "LTAI5tEBXGewpHSLiSxyx6Bf",
|
||||
"AccessKeySecret": "w29b8wkw6XQVL8GWXgp3ZesgYeDKvf",
|
||||
"VodBucketName": "outin-5277bbb52bec11f08dbd00163e169e2b.oss-cn-beijing.aliyuncs.com",
|
||||
"BucketName": "qyzh-qb",
|
||||
"Region": "beijing",
|
||||
"RoleArn": "acs:ram::1064745380176636:role/aliyunosstokengeneratorrole",
|
||||
"DurationSeconds": 3600, //过期时间(秒)
|
||||
"Endpoint": "oss-cn-beijing.aliyuncs.com",
|
||||
"ProjectName": "QuestionBank",
|
||||
"Domain": "https://qyzh-qb.oss-cn-beijing.aliyuncs.com/"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user