diff --git a/FileService/Caching/CacheResumableInfoService.cs b/FileService/Caching/CacheResumableInfoService.cs index 0aff7e9..840b541 100644 --- a/FileService/Caching/CacheResumableInfoService.cs +++ b/FileService/Caching/CacheResumableInfoService.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging; using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.IO; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; @@ -36,7 +37,7 @@ namespace Ufangx.FileServices.Caching throw new ArgumentException("message", nameof(fileName)); } - string cleanKey = $"StoreName={storeName}&FileName={fileName}&FileType={fileType}&FileSize={fileSize}&BlobSize={blobSize}&BlobCount={blobCount}&user={contextAccessor?.HttpContext?.User?.Identity?.Name}"; + string cleanKey = $"StoreName={Path.GetDirectoryName(storeName).Replace('\\','/').ToLower()}&FileName={fileName.ToLower()}&FileType={fileType?.ToLower()}&FileSize={fileSize}&BlobSize={blobSize}&BlobCount={blobCount}&user={contextAccessor?.HttpContext?.User?.Identity?.Name?.ToLower()}"; byte[] data; using (var md5 = MD5.Create()) { diff --git a/FileService/FileServices.csproj b/FileService/FileServices.csproj index a1891ff..eb83785 100644 --- a/FileService/FileServices.csproj +++ b/FileService/FileServices.csproj @@ -1,4 +1,4 @@ - + netstandard2.0;netcoreapp2.0;netstandard2.1;netcoreapp3.0 @@ -13,7 +13,7 @@ git file service web uploader html5 uploader breakpoint renewal Copyright (c) 2020-$([System.DateTime]::Now.Year) Jackson.Bruce - 1.0.0-beta.1 + 1.0.2-beta diff --git a/FileService/Middlewares/ResumableInfoDeleteUploaderMiddleware.cs b/FileService/Middlewares/ResumableInfoDeleteUploaderMiddleware.cs index 612acb9..33a9133 100644 --- a/FileService/Middlewares/ResumableInfoDeleteUploaderMiddleware.cs +++ b/FileService/Middlewares/ResumableInfoDeleteUploaderMiddleware.cs @@ -19,7 +19,7 @@ namespace Ufangx.FileServices.Middlewares } protected override async Task Handler(HttpContext context) { - string key = context.Request.Form["key"]; + string key = context.Request.Query["key"]; var service= context.RequestServices.GetRequiredService(); await WriteJsonAsync(context, await service.DeleteBlobs(key)); } diff --git a/TestWeb/Controllers/HomeController.cs b/TestWeb/Controllers/HomeController.cs index c93e500..ec1cc29 100644 --- a/TestWeb/Controllers/HomeController.cs +++ b/TestWeb/Controllers/HomeController.cs @@ -6,6 +6,9 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using TestWeb.Models; +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication.Cookies; +using System.Security.Claims; namespace TestWeb.Controllers { @@ -18,8 +21,16 @@ namespace TestWeb.Controllers _logger = logger; } - public IActionResult Index() + public async Task Index() { + if (!User.Identity.IsAuthenticated) { + var identity = new ClaimsIdentity("form"); + identity.AddClaims(new Claim[] { + new Claim(ClaimTypes.Sid,"uk"), + new Claim(ClaimTypes.Name,"admin") + }); + await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,new ClaimsPrincipal(identity),new AuthenticationProperties() { IsPersistent=true }); + } return View(); } diff --git a/TestWeb/Startup.cs b/TestWeb/Startup.cs index 115f897..1fd7b8b 100644 --- a/TestWeb/Startup.cs +++ b/TestWeb/Startup.cs @@ -27,9 +27,12 @@ namespace TestWeb // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + services.AddDistributedMemoryCache(); + services.AddAuthentication().AddCookie(); services.AddHttpContextAccessor(); - services.AddFileServices(opt => { - opt.DefaultScheme = "documents";//ĬÈÏÊÇÎĵµ´¦Àí·½°¸ + services.AddFileServices(opt => + { + opt.DefaultScheme = "Document";//ĬÈÏÊÇÎĵµ´¦Àí·½°¸ opt.AddAuthenticationScheme(CookieAuthenticationDefaults.AuthenticationScheme);//Éí·ÝÈÏÖ¤·½°¸Ãû³Æ //Îļþ±£´æÊ±ÐÂÎļþµÄÃüÃû¹æÔò opt.RuleOptions = new Ufangx.FileServices.Models.FileNameRuleOptions() @@ -41,27 +44,34 @@ namespace TestWeb }) //ÕÕÆ¬´¦Àí·½°¸ - .AddScheme("pictures", opt => { + .AddScheme("pictures", opt => + { opt.StoreDirectory = "wwwroot/pictures";//ͼƬ´æ´¢µÄĿ¼ opt.SupportExtensions = new string[] { ".jpg", ".png" };//Ö§³ÖµÄÀ©Õ¹Ãû opt.HandlerType = null;//ÉÏ´«³É¹¦ºóµÄÎļþ´¦ÀíÀàÐÍ£¬¸ÃÀàÐͱØÐëʵÏÖIFileHandler½Ó¿Ú opt.LimitedSize = 1024 * 1024 * 4;//Îļþ´óСµÄ×î´óÏÞÖÆÖµ£¬×Ö½ÚΪµ¥Î» }) - .AddScheme("documents",opt => opt.StoreDirectory = "wwwroot/documents")//Îĵµ´¦Àí·½°¸ + .AddScheme("Document", opt => opt.StoreDirectory = "wwwroot/documents")//Îĵµ´¦Àí·½°¸ //.AddScheme(name:"videos",storeDirectory:"",supportExtensions:new string[] { },LimitedSize:1024*1024*500)//ÊÓÆµ´¦Àí·½°¸ - //.AddLocalServices(o => o.StorageRootDir = hostEnvironment.ContentRootPath)//±¾µØÎļþϵͳ£¬Îļþ´æÔÚ±¾µØ + .AddLocalServices(o => o.StorageRootDir = hostEnvironment.ContentRootPath);//±¾µØÎļþϵͳ£¬Îļþ´æÔÚ±¾µØ //ÆßÅ£´æ´¢·þÎñ - .AddQiniuFileService(opt => { - opt.AccessKey = "";// - opt.SecretKey = ""; - opt.BasePath = ""; - opt.Bucket = ""; - opt.Domain = ""; - opt.ChunkUnit = Qiniu.Storage.ChunkUnit.U1024K; - opt.Zone = "ZoneCnEast"; + //.AddQiniuFileService(opt => { + // opt.AccessKey = "";// + // opt.SecretKey = ""; + // opt.BasePath = ""; + // opt.Bucket = ""; + // opt.Domain = ""; + // opt.ChunkUnit = Qiniu.Storage.ChunkUnit.U1024K; + // opt.Zone = "ZoneCnEast"; + //}); + services.AddCors(options => + { + options.AddPolicy("cors", builder => + { + builder.AllowCredentials().AllowAnyMethod().AllowAnyHeader().WithOrigins("http://localhost:9000"); }); - + }); services.AddControllersWithViews(); } @@ -81,6 +91,7 @@ namespace TestWeb app.UseHttpsRedirection(); app.UseStaticFiles(); + app.UseCors("cors"); app.UseRouting(); app.UseAuthorization(); diff --git a/TestWeb/TestWeb.csproj b/TestWeb/TestWeb.csproj index c193fe2..0d688f5 100644 --- a/TestWeb/TestWeb.csproj +++ b/TestWeb/TestWeb.csproj @@ -12,7 +12,14 @@ - + + + + + + + +