Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e90cc2d86e | ||
|
|
3cbd8b7559 | ||
|
|
d54b71badb | ||
|
|
ddeb2948b7 | ||
|
|
fb1ce7d931 | ||
|
|
c117d9ef1f |
@@ -11,7 +11,7 @@ jobs:
|
|||||||
- name: Setup .NET Core
|
- name: Setup .NET Core
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: '3.1.101'
|
dotnet-version: '5.0.0'
|
||||||
- name: Build
|
- name: Build
|
||||||
run: dotnet build
|
run: dotnet build
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -112,7 +112,11 @@ namespace YYApi
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IApplicationBuilder UseYYUpload(this IApplicationBuilder builder)
|
public static IApplicationBuilder UseYYUpload(this IApplicationBuilder builder)
|
||||||
{
|
{
|
||||||
return builder.UseStaticFiles();
|
return builder.UseStaticFiles(new StaticFileOptions
|
||||||
|
{
|
||||||
|
DefaultContentType = "application/x-msdownload",
|
||||||
|
ServeUnknownFileTypes = true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+17
-5
@@ -23,20 +23,23 @@ namespace YYApi.Helpers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string Set(int id, string type = "user")
|
public string Login(int id, string type = "user", string token = null)
|
||||||
{
|
{
|
||||||
return Set(id, new[] { type });
|
return Login(id, new[] { type }, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 产生一个TOken并记录用户ID角色[多角色]
|
/// 产生一个Token并记录用户ID角色[多角色]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string Set(int id, string[] type)
|
public string Login(int id, string[] type, string uuid = null)
|
||||||
{
|
{
|
||||||
var uuid = Guid.NewGuid().ToString();
|
if (uuid == null)
|
||||||
|
{
|
||||||
|
uuid = Guid.NewGuid().ToString();
|
||||||
|
}
|
||||||
var loginItem = new YYLoginItem
|
var loginItem = new YYLoginItem
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
@@ -46,5 +49,14 @@ namespace YYApi.Helpers
|
|||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 退出登陆
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="uuid">登陆标识</param>
|
||||||
|
public void Logout(string uuid)
|
||||||
|
{
|
||||||
|
Cache.Remove(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-4
@@ -33,6 +33,12 @@ namespace YYApi.Helpers
|
|||||||
Env = env;
|
Env = env;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class YYUploadInfo
|
||||||
|
{
|
||||||
|
public string Path { get; set; }
|
||||||
|
public int Size { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 保存base64文件,如果有标头按照标头自动识别
|
/// 保存base64文件,如果有标头按照标头自动识别
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -41,7 +47,7 @@ namespace YYApi.Helpers
|
|||||||
/// <param name="path">存放路径</param>
|
/// <param name="path">存放路径</param>
|
||||||
/// <param name="fileName">文件名</param>
|
/// <param name="fileName">文件名</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string SaveFile(string base64, string ext = null, string path = null, string fileName = null)
|
public YYUploadInfo SaveFile(string base64, string ext = null, string path = null, string fileName = null)
|
||||||
{
|
{
|
||||||
byte[] bt;
|
byte[] bt;
|
||||||
var filePath = FilePath + path;
|
var filePath = FilePath + path;
|
||||||
@@ -68,15 +74,30 @@ namespace YYApi.Helpers
|
|||||||
{
|
{
|
||||||
bt = Convert.FromBase64String(base64);
|
bt = Convert.FromBase64String(base64);
|
||||||
}
|
}
|
||||||
|
var fn = fileName + (string.IsNullOrEmpty(ext) ? string.Empty : $".{ext}");
|
||||||
|
return WriteFile(filePath, fn, bt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 把数据写入文件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filePath"></param>
|
||||||
|
/// <param name="fileName"></param>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public YYUploadInfo WriteFile(string filePath, string fileName, byte[] data)
|
||||||
|
{
|
||||||
var realPath = Directory.GetCurrentDirectory() + "/wwwroot" + filePath;
|
var realPath = Directory.GetCurrentDirectory() + "/wwwroot" + filePath;
|
||||||
if (!Directory.Exists(realPath))
|
if (!Directory.Exists(realPath))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(realPath);
|
Directory.CreateDirectory(realPath);
|
||||||
}
|
}
|
||||||
var fn = fileName + (string.IsNullOrEmpty(ext) ? string.Empty : $".{ext}");
|
File.WriteAllBytes(realPath + fileName, data);
|
||||||
File.WriteAllBytes(realPath + fn, bt);
|
return new YYUploadInfo
|
||||||
return filePath + fn;
|
{
|
||||||
|
Path = filePath + fileName,
|
||||||
|
Size = data.Length
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,3 +62,7 @@ app.UseYYAuth();
|
|||||||
#Startup.cs
|
#Startup.cs
|
||||||
app.UseYYException();
|
app.UseYYException();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### TODO:
|
||||||
|
1. 增加HANGFIRE 支持redis和sqlite 存储, 支持 基于其他系统的TOKEN认证和独立账号密码认证
|
||||||
|
|||||||
+6
-6
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<PackOnBuild>true</PackOnBuild>
|
<PackOnBuild>true</PackOnBuild>
|
||||||
<Version>0.2.3</Version>
|
<Version>0.2.3</Version>
|
||||||
@@ -23,12 +23,12 @@
|
|||||||
<Folder Include="Exceptions\" />
|
<Folder Include="Exceptions\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.0.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.5.1" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.0.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.5.1" />
|
||||||
<PackageReference Include="HangFire.Core" Version="1.7.9" />
|
<PackageReference Include="HangFire.Core" Version="1.7.11" />
|
||||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.9" />
|
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.11" />
|
||||||
<PackageReference Include="Hangfire.Console" Version="1.4.2" />
|
<PackageReference Include="Hangfire.Console" Version="1.4.2" />
|
||||||
<PackageReference Include="Hangfire.Redis.StackExchange" Version="1.8.1" />
|
<PackageReference Include="Hangfire.Redis.StackExchange" Version="1.8.4" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ProjectExtensions>
|
<ProjectExtensions>
|
||||||
<MonoDevelop>
|
<MonoDevelop>
|
||||||
|
|||||||
Reference in New Issue
Block a user