Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddeb2948b7 | ||
|
|
fb1ce7d931 | ||
|
|
c117d9ef1f | ||
|
|
9b38ee9b39 |
@@ -41,7 +41,7 @@ namespace YYApi.Attributes
|
|||||||
throw new YYApiException(401);
|
throw new YYApiException(401);
|
||||||
}
|
}
|
||||||
//检测用户类型
|
//检测用户类型
|
||||||
if (!Types.Contains(loginInfo.Type))
|
if (Types.Intersect(loginInfo.Type).Count() == 0)
|
||||||
{
|
{
|
||||||
throw new YYApiException(403);
|
throw new YYApiException(403);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,6 @@ namespace YYApi.Communications
|
|||||||
//登录用户的ID
|
//登录用户的ID
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
//登录用户来源
|
//登录用户来源
|
||||||
public string Type { get; set; }
|
public string[] Type { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+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>
|
||||||
|
|||||||
@@ -24,6 +24,17 @@ namespace YYApi.Helpers
|
|||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string Set(int id, string type = "user")
|
public string Set(int id, string type = "user")
|
||||||
|
{
|
||||||
|
return Set(id, new[] { type });
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 产生一个TOken并记录用户ID角色[多角色]
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public string Set(int id, string[] type)
|
||||||
{
|
{
|
||||||
var uuid = Guid.NewGuid().ToString();
|
var uuid = Guid.NewGuid().ToString();
|
||||||
var loginItem = new YYLoginItem
|
var loginItem = new YYLoginItem
|
||||||
|
|||||||
+12
-2
@@ -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;
|
||||||
@@ -76,7 +82,11 @@ namespace YYApi.Helpers
|
|||||||
}
|
}
|
||||||
var fn = fileName + (string.IsNullOrEmpty(ext) ? string.Empty : $".{ext}");
|
var fn = fileName + (string.IsNullOrEmpty(ext) ? string.Empty : $".{ext}");
|
||||||
File.WriteAllBytes(realPath + fn, bt);
|
File.WriteAllBytes(realPath + fn, bt);
|
||||||
return filePath + fn;
|
return new YYUploadInfo
|
||||||
|
{
|
||||||
|
Path = filePath + fn,
|
||||||
|
Size = bt.Length
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user