From 687160e0ae56aa6135c2c5540f7104cf3523af38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Thu, 9 Jun 2022 08:37:31 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Infrastructure/Enums/StoreType.cs | 8 ++++- Infrastructure/OptionsSetting.cs | 1 + .../Controllers/CommonController.cs | 8 +++-- ZR.Admin.WebApi/appsettings.json | 4 +-- ZR.Service/System/SysFileService.cs | 29 +++++++++---------- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/Infrastructure/Enums/StoreType.cs b/Infrastructure/Enums/StoreType.cs index 79d8e6d..dcc28ca 100644 --- a/Infrastructure/Enums/StoreType.cs +++ b/Infrastructure/Enums/StoreType.cs @@ -29,6 +29,12 @@ namespace Infrastructure.Enums /// 七牛 /// [Description("七牛云")] - QINIU = 4 + QINIU = 4, + + /// + /// 远程 + /// + [Description("远程")] + REMOTE = 5 } } diff --git a/Infrastructure/OptionsSetting.cs b/Infrastructure/OptionsSetting.cs index 3c88ce3..afd3dff 100644 --- a/Infrastructure/OptionsSetting.cs +++ b/Infrastructure/OptionsSetting.cs @@ -31,6 +31,7 @@ namespace Infrastructure public class Upload { public string UploadUrl { get; set; } + public string LocalSavePath { get; set; } } /// /// 阿里云存储 diff --git a/ZR.Admin.WebApi/Controllers/CommonController.cs b/ZR.Admin.WebApi/Controllers/CommonController.cs index 880156c..cd10476 100644 --- a/ZR.Admin.WebApi/Controllers/CommonController.cs +++ b/ZR.Admin.WebApi/Controllers/CommonController.cs @@ -110,13 +110,15 @@ namespace ZR.Admin.WebApi.Controllers switch (storeType) { case StoreType.LOCAL: - string savePath = AppSettings.App(new string[] { "Upload", "localSavePath" }); - if (savePath.IsEmpty()) + string savePath = Path.Combine(WebHostEnvironment.WebRootPath); + if (fileDir.IsEmpty()) { - savePath = Path.Combine(WebHostEnvironment.WebRootPath, "uploads"); + fileDir = AppSettings.App(new string[] { "Upload", "localSavePath" }); } file = await SysFileService.SaveFileToLocal(savePath, fileName, fileDir, HttpContext.GetName(), formFile); break; + case StoreType.REMOTE: + break; case StoreType.ALIYUN: if ((fileSize / 1024) > MaxContentLength) { diff --git a/ZR.Admin.WebApi/appsettings.json b/ZR.Admin.WebApi/appsettings.json index 20fecc6..01e4874 100644 --- a/ZR.Admin.WebApi/appsettings.json +++ b/ZR.Admin.WebApi/appsettings.json @@ -20,8 +20,8 @@ }, "DemoMode": false, //是否演示模式 "Upload": { - "UploadUrl": "http://localhost:8888", - "localSavePath": "" //本地上传文件存储目录/home/website/uploads + "UploadUrl": "http://localhost:8888", //本地存储资源访问路径 + "localSavePath": "uploads" //本地上传默认文件存储目录 wwwroot/uploads }, //阿里云存储配置 "ALIYUN_OSS": { diff --git a/ZR.Service/System/SysFileService.cs b/ZR.Service/System/SysFileService.cs index 3a2abf8..2a4c6e3 100644 --- a/ZR.Service/System/SysFileService.cs +++ b/ZR.Service/System/SysFileService.cs @@ -1,18 +1,17 @@ -using Infrastructure.Attribute; -using Microsoft.AspNetCore.Http; -using System.IO; -using ZR.Service.System.IService; -using ZR.Common; -using Infrastructure; -using System; -using System.Text; -using System.Security.Cryptography; -using System.Net; -using ZR.Model.System; -using ZR.Repository.System; +using Infrastructure; +using Infrastructure.Attribute; using Infrastructure.Extensions; -using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; +using System; +using System.IO; +using System.Net; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; +using ZR.Common; +using ZR.Model.System; +using ZR.Service.System.IService; namespace ZR.Service.System { @@ -44,7 +43,7 @@ namespace ZR.Service.System { string fileExt = Path.GetExtension(formFile.FileName); fileName = (fileName.IsEmpty() ? HashFileName() : fileName) + fileExt; - + string filePath = GetdirPath(fileDir); string finalFilePath = Path.Combine(rootPath, filePath, fileName); double fileSize = Math.Round(formFile.Length / 1024.0, 2); @@ -58,7 +57,7 @@ namespace ZR.Service.System { await formFile.CopyToAsync(stream); } - string uploadUrl = SysConfigService.GetSysConfigByKey("sys.file.uploadUrl")?.ConfigValue ?? OptionsSetting.Upload.UploadUrl; + string uploadUrl = OptionsSetting.Upload.UploadUrl; string accessPath = string.Concat(uploadUrl, "/", filePath.Replace("\\", "/"), "/", fileName); SysFile file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", filePath, userName) { From d74b350f866d9317ba1143630a10dbdb3b76f040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Thu, 9 Jun 2022 08:39:02 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=A4=B4=E5=83=8F=E5=AD=98=E5=82=A8=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Admin.WebApi/Controllers/System/SysProfileController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs b/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs index c531924..db3be8d 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs @@ -130,7 +130,7 @@ namespace ZR.Admin.WebApi.Controllers.System LoginUser loginUser = Framework.JwtUtil.GetLoginUser(HttpContext); if (formFile == null) throw new CustomException("请选择文件"); - SysFile file = await FileService.SaveFileToLocal(hostEnvironment.WebRootPath, "", "", HttpContext.GetName(), formFile); + SysFile file = await FileService.SaveFileToLocal(hostEnvironment.WebRootPath, "", "avatar", HttpContext.GetName(), formFile); UserService.UpdatePhoto(new SysUser() { Avatar = file.AccessUrl, UserId = loginUser.UserId }); return SUCCESS(new { imgUrl = file.AccessUrl }); From 756dc6635089f7dabd24eff1f2db954d186779a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Thu, 9 Jun 2022 08:41:29 +0800 Subject: [PATCH 3/4] update SysMenuService.cs --- ZR.Service/System/SysMenuService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZR.Service/System/SysMenuService.cs b/ZR.Service/System/SysMenuService.cs index 105b710..9154000 100644 --- a/ZR.Service/System/SysMenuService.cs +++ b/ZR.Service/System/SysMenuService.cs @@ -86,7 +86,7 @@ namespace ZR.Service var list = MenuRepository.GetList(f => f.parentId == menuId).OrderBy(f => f.orderNum).ToList(); Context.ThenMapper(list, item => { - item.SubNum = Context.Queryable().SetContext(x => x.parentId, () => item.MenuId, item).Count(); + item.SubNum = Context.Queryable().SetContext(x => x.parentId, () => item.MenuId, item).Count; }); return list; } From 17008fc9c9912aed108c24e2d7b3d878ab6e8483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Thu, 9 Jun 2022 08:41:49 +0800 Subject: [PATCH 4/4] update appsettings.json --- ZR.Admin.WebApi/appsettings.json | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/ZR.Admin.WebApi/appsettings.json b/ZR.Admin.WebApi/appsettings.json index 01e4874..3789b8b 100644 --- a/ZR.Admin.WebApi/appsettings.json +++ b/ZR.Admin.WebApi/appsettings.json @@ -56,20 +56,12 @@ }, //接口请求限制 "IpRateLimiting": { - //例如设置了5次每分钟访问限流。当False时:项目中每个接口都加入计数,不管你访问哪个接口,只要在一分钟内累计够5次,将禁止访问。 - //True:当一分钟请求了5次GetData接口,则该接口将在时间段内禁止访问,但是还可以访问PostData()5次,总得来说是每个接口都有5次在这一分钟,互不干扰。 "EnableEndpointRateLimiting": true, - //false,拒绝的API调用不会添加到调用次数计数器上;如 客户端每秒发出3个请求并且您设置了每秒一个调用的限制,则每分钟或每天计数器等其他限制将仅记录第一个调用,即成功的API调用。如果您希望被拒绝的API调用计入其他时间的显示(分钟,小时等) - //,则必须设置StackBlockedRequests为true。 "StackBlockedRequests": false, "RealIpHeader": "X-Real-IP", - //取白名单的客户端ID。如果此标头中存在客户端ID并且与ClientWhitelist中指定的值匹配,则不应用速率限制。 "ClientIdHeader": "X-ClientId", "HttpStatusCode": 429, - //端点白名单 "EndpointWhitelist": [ "post:/system/dict/data/types", "*:/msghub/negotiate", "*:/LogOut" ], - //客户端白名单 - //"ClientWhitelist": [ "dev-id-1", "dev-id-2" ], "QuotaExceededResponse": { "Content": "{{\"code\":429,\"msg\":\"访问过于频繁,请稍后重试\"}}", "ContentType": "application/json", @@ -95,27 +87,6 @@ "Period": "3s", "Limit": 1 } - //{ - // "Endpoint": "*", - // //时间段,格式:{数字}{单位};可使用单位:s, m, h, d - // "Period": "1s", - // "Limit": 2 - //} - //{ - // "Endpoint": "*", - // "Period": "15m", - // "Limit": 100 - //}, - //{ - // "Endpoint": "*", - // "Period": "12h", - // "Limit": 1000 - //}, - //{ - // "Endpoint": "*", - // "Period": "7d", - // "Limit": 10000 - //} ], "IpRateLimitPolicies": { //ip规则