修改续传key的构建,修改删除续传信息时失败的bug,添加测试

This commit is contained in:
Jackson.Bruce
2020-12-21 16:34:48 +08:00
parent 9c315f73f4
commit 18517b5e3b
6 changed files with 50 additions and 20 deletions

View File

@@ -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())
{

View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp2.0;netstandard2.1;netcoreapp3.0</TargetFrameworks>
@@ -13,7 +13,7 @@
<RepositoryType>git</RepositoryType>
<PackageTags>file service web uploader html5 uploader breakpoint renewal</PackageTags>
<Copyright>Copyright (c) 2020-$([System.DateTime]::Now.Year) Jackson.Bruce</Copyright>
<Version>1.0.0-beta.1</Version>
<Version>1.0.2-beta</Version>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)|$(Platform)'=='netstandard2.0|AnyCPU'">

View File

@@ -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<IResumableService>();
await WriteJsonAsync(context, await service.DeleteBlobs(key));
}

View File

@@ -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<IActionResult> 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();
}

View File

@@ -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";//Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
services.AddFileServices(opt =>
{
opt.DefaultScheme = "Document";//Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
opt.AddAuthenticationScheme(CookieAuthenticationDefaults.AuthenticationScheme);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
opt.RuleOptions = new Ufangx.FileServices.Models.FileNameRuleOptions()
@@ -41,27 +44,34 @@ namespace TestWeb
})
//<2F><>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
.AddScheme("pictures", opt => {
.AddScheme("pictures", opt =>
{
opt.StoreDirectory = "wwwroot/pictures";//ͼƬ<CDBC><EFBFBD><E6B4A2>Ŀ¼
opt.SupportExtensions = new string[] { ".jpg", ".png" };//֧<>ֵ<EFBFBD><D6B5><EFBFBD>չ<EFBFBD><D5B9>
opt.HandlerType = null;//<2F>ϴ<EFBFBD><CFB4>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD>ʵ<EFBFBD><CAB5>IFileHandler<65>ӿ<EFBFBD>
opt.LimitedSize = 1024 * 1024 * 4;//<2F>ļ<EFBFBD><C4BC><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>ֽ<EFBFBD>Ϊ<EFBFBD><CEAA>λ
})
.AddScheme("documents",opt => opt.StoreDirectory = "wwwroot/documents")//<2F>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
.AddScheme("Document", opt => opt.StoreDirectory = "wwwroot/documents")//<2F>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//.AddScheme<VideoService>(name:"videos",storeDirectory:"",supportExtensions:new string[] { },LimitedSize:1024*1024*500)//<2F><>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//.AddLocalServices(o => o.StorageRootDir = hostEnvironment.ContentRootPath)//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD>
.AddLocalServices(o => o.StorageRootDir = hostEnvironment.ContentRootPath);//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD>
//<2F><>ţ<EFBFBD><EFBFBD><E6B4A2><EFBFBD><EFBFBD>
.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();

View File

@@ -12,7 +12,14 @@
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
<PackageReference Include="Qiniu.FileService" Version="1.0.0-beta.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FileService\FileServices.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\documents\" />
</ItemGroup>