Skip to content

使用 Headers.Append 替换 Headers.Add #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: net8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Infrastructure/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Infrastructure.Extensions;
using Infrastructure.Model;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using Newtonsoft.Json;
Expand Down Expand Up @@ -72,7 +73,7 @@ protected IActionResult ExportExcel(string path, string fileName)
}
var stream = System.IO.File.OpenRead(path); //创建文件流

Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
Response.Headers.Append("Access-Control-Expose-Headers", "Content-Disposition");
return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", HttpUtility.UrlEncode(fileName));
}

Expand All @@ -89,7 +90,7 @@ protected IActionResult DownFile(string path, string fileName)
return NotFound();
}
var stream = System.IO.File.OpenRead(path); //创建文件流
Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
Response.Headers.Append("Access-Control-Expose-Headers", "Content-Disposition");
return File(stream, "application/octet-stream", HttpUtility.UrlEncode(fileName));
}

Expand Down
3 changes: 2 additions & 1 deletion Infrastructure/WebExtensions/JwtExtension.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Infrastructure;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using System;
Expand Down Expand Up @@ -27,7 +28,7 @@ public static void AddJwt(this IServiceCollection services)
if (context.Exception.GetType() == typeof(SecurityTokenExpiredException))
{
Console.WriteLine("jwt过期了");
context.Response.Headers.Add("Token-Expired", "true");
context.Response.Headers.Append("Token-Expired", "true");
}

return Task.CompletedTask;
Expand Down
10 changes: 5 additions & 5 deletions Infrastructure/ZR.Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

<ItemGroup>
<PackageReference Include="AspectCore.Abstractions" Version="2.4.0" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="8.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="UAParser" Version="3.1.47" />
<PackageReference Include="IPTools.China" Version="1.6.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
<PackageReference Include="JinianNet.JNTemplate" Version="2.4.1" />
<PackageReference Include="MiniExcel" Version="1.31.2" />
<PackageReference Include="CSRedisCore" Version="3.8.801" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.10" />
<PackageReference Include="JinianNet.JNTemplate" Version="2.4.2" />
<PackageReference Include="MiniExcel" Version="1.34.2" />
<PackageReference Include="CSRedisCore" Version="3.8.803" />
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
</ItemGroup>

Expand Down
34 changes: 14 additions & 20 deletions ZR.Admin.WebApi/Controllers/Article/ArticleCategoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,13 @@ namespace ZR.Admin.WebApi.Controllers
/// <summary>
/// 文章目录Controller
/// </summary>
/// <param name="ArticleCategoryService">
/// 文章目录接口
/// </param>
[Route("article/ArticleCategory")]
[ApiExplorerSettings(GroupName = "article")]
public class ArticleCategoryController : BaseController
public class ArticleCategoryController(IArticleCategoryService ArticleCategoryService) : BaseController
{
/// <summary>
/// 文章目录接口
/// </summary>
private readonly IArticleCategoryService _ArticleCategoryService;

public ArticleCategoryController(IArticleCategoryService ArticleCategoryService)
{
_ArticleCategoryService = ArticleCategoryService;
}

/// <summary>
/// 查询文章目录列表
Expand All @@ -32,7 +26,7 @@ public ArticleCategoryController(IArticleCategoryService ArticleCategoryService)
[AllowAnonymous]
public IActionResult QueryArticleCategory([FromQuery] ArticleCategoryQueryDto parm)
{
var response = _ArticleCategoryService.GetList(parm);
var response = ArticleCategoryService.GetList(parm);
return SUCCESS(response);
}

Expand All @@ -45,7 +39,7 @@ public IActionResult QueryArticleCategory([FromQuery] ArticleCategoryQueryDto pa
[AllowAnonymous]
public IActionResult QueryTreeArticleCategory([FromQuery] ArticleCategoryQueryDto parm)
{
var response = _ArticleCategoryService.GetTreeList(parm);
var response = ArticleCategoryService.GetTreeList(parm);
return SUCCESS(response);
}

Expand All @@ -59,7 +53,7 @@ public IActionResult QueryTreeArticleCategory([FromQuery] ArticleCategoryQueryDt
//[ActionPermissionFilter(Permission = "articlecategory:query")]
public IActionResult GetArticleCategory(int CategoryId)
{
var response = _ArticleCategoryService.GetFirst(x => x.CategoryId == CategoryId);
var response = ArticleCategoryService.GetFirst(x => x.CategoryId == CategoryId);

return SUCCESS(response);
}
Expand All @@ -73,7 +67,7 @@ public IActionResult GetArticleCategory(int CategoryId)
//[ActionPermissionFilter(Permission = "articlecategory:query")]
public IActionResult GetArticleCategoryByType(int categoryType)
{
var response = _ArticleCategoryService.GetFirst(x => x.CategoryType == categoryType);
var response = ArticleCategoryService.GetFirst(x => x.CategoryType == categoryType);

return SUCCESS(response);
}
Expand All @@ -89,7 +83,7 @@ public IActionResult GetArticleCategoryByType(int categoryType)
public IActionResult AddArticleCategory([FromBody] ArticleCategoryDto parm)
{
var modal = parm.Adapt<ArticleCategory>().ToCreate(HttpContext);
var response = _ArticleCategoryService.AddArticleCategory(modal);
var response = ArticleCategoryService.AddArticleCategory(modal);

return ToResponse(response);
}
Expand All @@ -105,7 +99,7 @@ public IActionResult AddArticleCategory([FromBody] ArticleCategoryDto parm)
public IActionResult UpdateArticleCategory([FromBody] ArticleCategoryDto parm)
{
var modal = parm.Adapt<ArticleCategory>().ToUpdate(HttpContext);
var response = _ArticleCategoryService.Update(modal);
var response = ArticleCategoryService.Update(modal);

return ToResponse(response);
}
Expand All @@ -122,7 +116,7 @@ public IActionResult DeleteArticleCategory(string ids)
int[] idsArr = Tools.SpitIntArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }

var response = _ArticleCategoryService.Delete(idsArr);
var response = ArticleCategoryService.Delete(idsArr);

return ToResponse(response);
}
Expand All @@ -137,7 +131,7 @@ public IActionResult DeleteArticleCategory(string ids)
public IActionResult Export([FromQuery] ArticleCategoryQueryDto parm)
{
parm.PageSize = 10000;
var list = _ArticleCategoryService.GetList(parm).Result;
var list = ArticleCategoryService.GetList(parm).Result;

string sFileName = ExportExcel(list, "ArticleCategory", "文章目录");
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
Expand All @@ -150,7 +144,7 @@ public IActionResult Export([FromQuery] ArticleCategoryQueryDto parm)
[HttpGet("CategoryList")]
public IActionResult CategoryList()
{
var response = _ArticleCategoryService.GetAll();
var response = ArticleCategoryService.GetAll();
return SUCCESS(response);
}

Expand All @@ -166,7 +160,7 @@ public IActionResult CategoryList()
public IActionResult ChangeSort(int id = 0, int value = 0)
{
if (id <= 0) { return ToResponse(ApiResult.Error(101, "请求参数错误")); }
var response = _ArticleCategoryService.Update(w => w.CategoryId == id, it => new ArticleCategory ()
var response = ArticleCategoryService.Update(w => w.CategoryId == id, it => new ArticleCategory ()
{
CategoryId = id,
OrderNum = value
Expand Down
37 changes: 12 additions & 25 deletions ZR.Admin.WebApi/Controllers/Article/ArticleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,9 @@ namespace ZR.Admin.WebApi.Controllers
[Verify]
[Route("article")]
[ApiExplorerSettings(GroupName = "article")]
public class ArticleController : BaseController
public class ArticleController(
IArticleService articleService): BaseController
{
/// <summary>
/// 文章接口
/// </summary>
private readonly IArticleService _ArticleService;
private readonly IArticleCategoryService _ArticleCategoryService;

public ArticleController(
IArticleService ArticleService,
IArticleCategoryService articleCategoryService)
{
_ArticleService = ArticleService;
_ArticleCategoryService = articleCategoryService;
_ArticleService = ArticleService;
}

/// <summary>
/// 查询文章列表
Expand All @@ -37,7 +24,7 @@ public ArticleController(
[ActionPermissionFilter(Permission = "system:article:list")]
public IActionResult Query([FromQuery] ArticleQueryDto parm)
{
var response = _ArticleService.GetList(parm);
var response = articleService.GetList(parm);

return SUCCESS(response);
}
Expand All @@ -54,7 +41,7 @@ public IActionResult PassedMonents(string ids)
long[] idsArr = Tools.SpitLongArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"审核通过失败Id 不能为空")); }

return ToResponse(_ArticleService.Passed(idsArr));
return ToResponse(articleService.Passed(idsArr));
}

/// <summary>
Expand All @@ -69,7 +56,7 @@ public IActionResult RejectMonents(string ids, string reason = "")
long[] idsArr = Tools.SpitLongArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"審核拒绝失败Id 不能为空")); }

int result = _ArticleService.Reject(reason, idsArr);
int result = articleService.Reject(reason, idsArr);
return ToResponse(result);
}

Expand All @@ -81,7 +68,7 @@ public IActionResult RejectMonents(string ids, string reason = "")
public IActionResult QueryMyList([FromQuery] ArticleQueryDto parm)
{
parm.UserId = HttpContext.GetUId();
var response = _ArticleService.GetMyList(parm);
var response = articleService.GetMyList(parm);

return SUCCESS(response);
}
Expand All @@ -95,7 +82,7 @@ public IActionResult QueryMyList([FromQuery] ArticleQueryDto parm)
public IActionResult Get(int id)
{
long userId = HttpContext.GetUId();
var model = _ArticleService.GetArticle(id, userId);
var model = articleService.GetArticle(id, userId);

ApiResult apiResult = ApiResult.Success(model);

Expand All @@ -118,7 +105,7 @@ public IActionResult Create([FromBody] ArticleDto parm)
addModel.Location = HttpContextExtension.GetIpInfo(addModel.UserIP);
addModel.AuditStatus = Model.Enum.AuditStatusEnum.Passed;

return SUCCESS(_ArticleService.InsertReturnIdentity(addModel));
return SUCCESS(articleService.InsertReturnIdentity(addModel));
}

/// <summary>
Expand All @@ -132,7 +119,7 @@ public IActionResult Update([FromBody] ArticleDto parm)
{
parm.AuthorName = HttpContext.GetName();
var modal = parm.Adapt<Article>().ToUpdate(HttpContext);
var response = _ArticleService.UpdateArticle(modal);
var response = articleService.UpdateArticle(modal);

return SUCCESS(response);
}
Expand All @@ -146,7 +133,7 @@ public IActionResult Update([FromBody] ArticleDto parm)
[Log(Title = "置顶文章", BusinessType = BusinessType.UPDATE)]
public IActionResult Top([FromBody] Article parm)
{
var response = _ArticleService.TopArticle(parm);
var response = articleService.TopArticle(parm);

return SUCCESS(response);
}
Expand All @@ -160,7 +147,7 @@ public IActionResult Top([FromBody] Article parm)
[Log(Title = "是否公开", BusinessType = BusinessType.UPDATE)]
public IActionResult ChangePublic([FromBody] Article parm)
{
var response = _ArticleService.ChangeArticlePublic(parm);
var response = articleService.ChangeArticlePublic(parm);

return SUCCESS(response);
}
Expand All @@ -174,7 +161,7 @@ public IActionResult ChangePublic([FromBody] Article parm)
[Log(Title = "文章删除", BusinessType = BusinessType.DELETE)]
public IActionResult Delete(int id = 0)
{
var response = _ArticleService.Delete(id);
var response = articleService.Delete(id);
return SUCCESS(response);
}
}
Expand Down
26 changes: 10 additions & 16 deletions ZR.Admin.WebApi/Controllers/Article/ArticleTopicController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@ namespace ZR.Admin.WebApi.Controllers
/// <summary>
/// 文章话题
/// </summary>
/// <param name="ArticleTopicService">
/// 文章话题接口
/// </param>
[Verify]
[ApiExplorerSettings(GroupName = "article")]
[Route("article/ArticleTopic")]
public class ArticleTopicController : BaseController
public class ArticleTopicController(IArticleTopicService ArticleTopicService) : BaseController
{
/// <summary>
/// 文章话题接口
/// </summary>
private readonly IArticleTopicService _ArticleTopicService;

public ArticleTopicController(IArticleTopicService ArticleTopicService)
{
_ArticleTopicService = ArticleTopicService;
}

/// <summary>
/// 查询文章话题列表
Expand All @@ -34,7 +28,7 @@ public ArticleTopicController(IArticleTopicService ArticleTopicService)
[ActionPermissionFilter(Permission = "articletopic:list")]
public IActionResult QueryArticleTopic([FromQuery] ArticleTopicQueryDto parm)
{
var response = _ArticleTopicService.GetList(parm);
var response = ArticleTopicService.GetList(parm);
return SUCCESS(response);
}

Expand All @@ -47,7 +41,7 @@ public IActionResult QueryArticleTopic([FromQuery] ArticleTopicQueryDto parm)
[ActionPermissionFilter(Permission = "articletopic:query")]
public IActionResult GetArticleTopic(long TopicId)
{
var response = _ArticleTopicService.GetInfo(TopicId);
var response = ArticleTopicService.GetInfo(TopicId);

var info = response.Adapt<ArticleTopicDto>();
return SUCCESS(info);
Expand All @@ -64,7 +58,7 @@ public IActionResult AddArticleTopic([FromBody] ArticleTopicDto parm)
{
var modal = parm.Adapt<ArticleTopic>().ToCreate(HttpContext);

var response = _ArticleTopicService.AddArticleTopic(modal);
var response = ArticleTopicService.AddArticleTopic(modal);

return SUCCESS(response);
}
Expand All @@ -79,7 +73,7 @@ public IActionResult AddArticleTopic([FromBody] ArticleTopicDto parm)
public IActionResult UpdateArticleTopic([FromBody] ArticleTopicDto parm)
{
var modal = parm.Adapt<ArticleTopic>().ToUpdate(HttpContext);
var response = _ArticleTopicService.UpdateArticleTopic(modal);
var response = ArticleTopicService.UpdateArticleTopic(modal);

return ToResponse(response);
}
Expand All @@ -95,7 +89,7 @@ public IActionResult DeleteArticleTopic([FromRoute] string ids)
{
var idArr = Tools.SplitAndConvert<long>(ids);

return ToResponse(_ArticleTopicService.Delete(idArr));
return ToResponse(ArticleTopicService.Delete(idArr));
}

/// <summary>
Expand All @@ -109,7 +103,7 @@ public IActionResult Export([FromQuery] ArticleTopicQueryDto parm)
{
parm.PageNum = 1;
parm.PageSize = 100000;
var list = _ArticleTopicService.ExportList(parm).Result;
var list = ArticleTopicService.ExportList(parm).Result;
if (list == null || list.Count <= 0)
{
return ToResponse(ResultCode.FAIL, "没有要导出的数据");
Expand Down
Loading