Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9bce77a08e | ||
|
|
8c7f4ac12f | ||
|
|
856c70d4ac | ||
|
|
dfa9fbf909 | ||
|
|
883315bc30 | ||
|
|
4ed517ac90 | ||
|
|
eacbbc3071 | ||
|
|
ee3a3a9d56 | ||
|
|
61672c5770 | ||
|
|
c6b9746603 | ||
|
|
f7e1b9be2a | ||
|
|
d0fe883e74 | ||
|
|
e4773f3154 |
@@ -3,20 +3,7 @@ name: PublishNugetPackage
|
||||
on: [create]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build Project
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Setup .NET Core
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: '3.1.101'
|
||||
- name: Build
|
||||
run: dotnet build
|
||||
|
||||
publish:
|
||||
needs: build
|
||||
name: Publish Project to Nuget
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@@ -24,11 +11,11 @@ jobs:
|
||||
- name: Setup .NET Core
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: '3.1.101'
|
||||
dotnet-version: '5.0.100'
|
||||
- name: Publish
|
||||
run: |
|
||||
version=`git describe --tags`
|
||||
dotnet pack --configuration release -p:PackageVersion=$version
|
||||
dotnet build --configuration release -p:PackageVersion=$version
|
||||
dotnet nuget push bin/release/Simcu.SimApi.$version.nupkg -k ${NUGET_APIKEY} -s https://www.nuget.org/api/v2/package
|
||||
env:
|
||||
NUGET_APIKEY: ${{ secrets.NUGET_APIKEY }}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using SimApi.Communications;
|
||||
using SimApi.Exceptions;
|
||||
@@ -14,6 +15,7 @@ namespace SimApi.Attributes
|
||||
{
|
||||
private string[] Types { get; }
|
||||
|
||||
|
||||
//默认是user登录类型
|
||||
public SimApiAuthAttribute()
|
||||
{
|
||||
@@ -32,6 +34,13 @@ namespace SimApi.Attributes
|
||||
Types = types;
|
||||
}
|
||||
|
||||
//只检测一种用户类型的快捷方式
|
||||
public SimApiAuthAttribute(string type, string url)
|
||||
{
|
||||
Types = new[] { type };
|
||||
new HttpPostAttribute(url);
|
||||
}
|
||||
|
||||
public override void OnActionExecuting(ActionExecutingContext context)
|
||||
{
|
||||
var loginInfo = (SimApiLoginItem)context.HttpContext.Items["LoginInfo"];
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace SimApi.Communications
|
||||
{
|
||||
IgnoreReadOnlyProperties = true,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
Converters = { new JsonStringEnumConverter() }
|
||||
Converters = {new JsonStringEnumConverter()}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -110,10 +110,13 @@ namespace SimApi.Communications
|
||||
/// 动态内容列表
|
||||
/// </summary>
|
||||
public T List { get; set; }
|
||||
|
||||
//当前页码
|
||||
public int Page { get; set; }
|
||||
|
||||
//每页条数
|
||||
public int Count { get; set; }
|
||||
|
||||
//总计条数
|
||||
public int Total { get; set; }
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace SimApi.Controllers
|
||||
/// <param name="condition">检测条件</param>
|
||||
/// <param name="code">错误代码</param>
|
||||
/// <param name="message">错误描述</param>
|
||||
protected static void ErrorWhenNull(object condition, int code = 404, string message = "请求的资源不存在")
|
||||
protected static void ErrorWhenNull(object condition, int code = 404, string message = "")
|
||||
{
|
||||
ErrorWhen(condition == null, code, message);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,10 @@ namespace SimApi.Helpers
|
||||
/// <param name="uuid">登陆标识</param>
|
||||
public void Logout(string uuid)
|
||||
{
|
||||
Cache.Remove(uuid);
|
||||
if (!string.IsNullOrEmpty(uuid))
|
||||
{
|
||||
Cache.Remove(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace SimApi.Middlewares
|
||||
httpContext.Items.Add("LoginInfo", JsonSerializer.Deserialize<SimApiLoginItem>(login));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Next(httpContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using SimApi.Communications;
|
||||
@@ -23,14 +24,34 @@ namespace SimApi.Middlewares
|
||||
|
||||
public async Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
if (context.Request.Headers.ContainsKey("Query-Id"))
|
||||
{
|
||||
context.Response.Headers["Query-Id"] = context.Request.Headers["Query-Id"];
|
||||
}
|
||||
|
||||
var response = new SimApiBaseResponse();
|
||||
try
|
||||
{
|
||||
await Next(context);
|
||||
if (context.Response.StatusCode != 200)
|
||||
{
|
||||
if (!new[] {301, 302}.Contains(context.Response.StatusCode))
|
||||
{
|
||||
throw new SimApiException(context.Response.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SimApiException ex)
|
||||
{
|
||||
response.SetCodeMsg(ex.Code, ex.Message);
|
||||
if (string.IsNullOrEmpty(ex.Message))
|
||||
{
|
||||
response.SetCode(ex.Code);
|
||||
}
|
||||
else
|
||||
{
|
||||
response.SetCodeMsg(ex.Code, ex.Message);
|
||||
}
|
||||
|
||||
ErrorResponse(context, response);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# YYApi 基于Asp.net Core 3的一个基础辅助包
|
||||
# YYApi 基于Asp.net Core 3/5的一个基础辅助包
|
||||
|
||||

|
||||
|
||||
|
||||
+7
-4
@@ -1,7 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<OutputType>Library</OutputType>
|
||||
<PackOnBuild>true</PackOnBuild>
|
||||
<Version>0.2.3</Version>
|
||||
@@ -11,10 +10,14 @@
|
||||
<IsPackable>true</IsPackable>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<ReleaseVersion>1.1.1</ReleaseVersion>
|
||||
<ReleaseVersion>5.0.0</ReleaseVersion>
|
||||
<SynchReleaseVersion>false</SynchReleaseVersion>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<PackageVersion>5.0.2</PackageVersion>
|
||||
<TargetFrameworks>net5.0;netcoreapp3.1</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(RunConfiguration)' == 'YYApi' " />
|
||||
<ItemGroup>
|
||||
<Folder Include="Helpers\" />
|
||||
<Folder Include="Communications\" />
|
||||
@@ -24,8 +27,8 @@
|
||||
<Folder Include="Exceptions\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.5.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.5.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.6.3" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.6.3" />
|
||||
</ItemGroup>
|
||||
<ProjectExtensions>
|
||||
<MonoDevelop>
|
||||
|
||||
+24
-11
@@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerUI;
|
||||
using SimApi.Middlewares;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
|
||||
namespace SimApi
|
||||
{
|
||||
@@ -13,6 +14,9 @@ namespace SimApi
|
||||
/// </summary>
|
||||
public static class Extensions
|
||||
{
|
||||
public static string DocumentTitle = "";
|
||||
public static string DocumentDescription = "";
|
||||
|
||||
//**********快捷添加**************
|
||||
|
||||
/// <summary>
|
||||
@@ -25,7 +29,16 @@ namespace SimApi
|
||||
public static IServiceCollection AddSimApi(this IServiceCollection builder, string title,
|
||||
string description = null)
|
||||
{
|
||||
return builder.AddSimApiAuth().AddSimApiDoc(title, description).AddCors().AddSimApiUpload();
|
||||
return builder.AddSimApiAuth().AddSimApiDoc(title, description).AddCors().AddSimApiUpload().Configure<ForwardedHeadersOptions>(options =>
|
||||
{
|
||||
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor |
|
||||
ForwardedHeaders.XForwardedProto;
|
||||
// Only loopback proxies are allowed by default.
|
||||
// Clear that restriction because forwarders are enabled by explicit
|
||||
// configuration.
|
||||
options.KnownNetworks.Clear();
|
||||
options.KnownProxies.Clear();
|
||||
}); ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -36,9 +49,9 @@ namespace SimApi
|
||||
/// <param name="staticFileroot"></param>
|
||||
/// <param name="submitMethods"></param>
|
||||
/// <returns></returns>
|
||||
public static IApplicationBuilder UseSimApi(this IApplicationBuilder builder, string title = "API文档", params SubmitMethod[] submitMethods)
|
||||
public static IApplicationBuilder UseSimApi(this IApplicationBuilder builder, params SubmitMethod[] submitMethods)
|
||||
{
|
||||
return builder.UseSimApiException().UseSimApiDoc(title, submitMethods).UseMiddleware<SimApiAuthMiddleware>().UseCors(x => x.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()).UseSimApiUpload();
|
||||
return builder.UseSimApiException().UseSimApiDoc(submitMethods).UseMiddleware<SimApiAuthMiddleware>().UseCors(x => x.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()).UseSimApiUpload().UseForwardedHeaders();
|
||||
}
|
||||
|
||||
|
||||
@@ -75,9 +88,11 @@ namespace SimApi
|
||||
public static IServiceCollection AddSimApiDoc(this IServiceCollection builder, string title,
|
||||
string description = null)
|
||||
{
|
||||
DocumentTitle = title;
|
||||
DocumentDescription = description;
|
||||
return builder.AddSwaggerGen(x =>
|
||||
{
|
||||
x.SwaggerDoc("api", new OpenApiInfo { Title = title, Description = description });
|
||||
x.SwaggerDoc("api", new OpenApiInfo { Title = DocumentTitle, Description = DocumentDescription });
|
||||
x.EnableAnnotations();
|
||||
x.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||
{
|
||||
@@ -126,14 +141,13 @@ namespace SimApi
|
||||
/// <param name="title">文档标题</param>
|
||||
/// <param name="submitMethods">文档支持的提交方式(如果不指定,默认使用POST)</param>
|
||||
/// <returns></returns>
|
||||
public static IApplicationBuilder UseSimApiDoc(this IApplicationBuilder builder, string title,
|
||||
params SubmitMethod[] submitMethods)
|
||||
public static IApplicationBuilder UseSimApiDoc(this IApplicationBuilder builder, params SubmitMethod[] submitMethods)
|
||||
{
|
||||
return builder.UseSwagger(x => x.RouteTemplate = "docs/{documentName}.json").UseSwaggerUI(x =>
|
||||
{
|
||||
x.RoutePrefix = "docs";
|
||||
x.DocumentTitle = title;
|
||||
x.SwaggerEndpoint("/docs/api.json", name: title);
|
||||
x.DocumentTitle = DocumentTitle;
|
||||
x.SwaggerEndpoint("/docs/api.json", name: DocumentTitle);
|
||||
x.EnableValidator();
|
||||
if (submitMethods.Length > 0)
|
||||
{
|
||||
@@ -156,10 +170,9 @@ namespace SimApi
|
||||
/// <param name="title">文档标题</param>
|
||||
/// <param name="submitMethods">API提交方式定义</param>
|
||||
/// <returns></returns>
|
||||
public static IApplicationBuilder UseSimApiDocEx(this IApplicationBuilder builder, string title = "API文档",
|
||||
params SubmitMethod[] submitMethods)
|
||||
public static IApplicationBuilder UseSimApiDocEx(this IApplicationBuilder builder, params SubmitMethod[] submitMethods)
|
||||
{
|
||||
return builder.UseSimApiException().UseSimApiDoc(title, submitMethods);
|
||||
return builder.UseSimApiException().UseSimApiDoc(submitMethods);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user