Uat_Study
parent
78e52831d1
commit
b5fc28bc18
|
@ -1,54 +1,91 @@
|
||||||
using Microsoft.AspNetCore.Builder;
|
using IRaCIS.Core.Domain.Share;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.StaticFiles;
|
using Microsoft.AspNetCore.StaticFiles;
|
||||||
|
using Microsoft.Extensions.FileProviders;
|
||||||
using Microsoft.Extensions.FileProviders.Physical;
|
using Microsoft.Extensions.FileProviders.Physical;
|
||||||
|
using Microsoft.Extensions.Hosting.Internal;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using Microsoft.VisualBasic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace IRaCIS.Core.API
|
namespace IRaCIS.Core.API
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
//public class MultiDiskStaticFilesMiddleware
|
|
||||||
//{
|
|
||||||
// public MultiDiskStaticFilesMiddleware(RequestDelegate next,IWebHostEnvironment webHostEnvironment, StaticFileOptions options)
|
|
||||||
// : base(next, webHostEnvironment, options)
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public override async Task InvokeAsync(HttpContext context)
|
public class MultiDiskStaticFilesMiddleware
|
||||||
// {
|
{
|
||||||
// try
|
private readonly RequestDelegate _next;
|
||||||
// {
|
private readonly IWebHostEnvironment _hostingEnv;
|
||||||
// await base.InvokeAsync(context);
|
private readonly StaticFileOptions _options;
|
||||||
// }
|
private readonly ILoggerFactory _loggerFactory;
|
||||||
// catch (FileNotFoundException)
|
|
||||||
// {
|
|
||||||
// var disks = GetDisks();
|
|
||||||
|
|
||||||
// foreach (var disk in disks)
|
public MultiDiskStaticFilesMiddleware(RequestDelegate next, IWebHostEnvironment hostingEnv, StaticFileOptions options, ILoggerFactory loggerFactory)
|
||||||
// {
|
{
|
||||||
// var fileInfo = new PhysicalFileInfo(new FileInfo(Path.Combine(disk, Options.RequestPath.Value)));
|
_next = next;
|
||||||
// if (fileInfo.Exists)
|
_hostingEnv = hostingEnv;
|
||||||
// {
|
_options = options;
|
||||||
// await SendFileAsync(context, fileInfo);
|
_loggerFactory = loggerFactory;
|
||||||
// return;
|
}
|
||||||
// }
|
|
||||||
// }
|
public async Task Invoke(HttpContext context)
|
||||||
|
{
|
||||||
|
var path = context.Request.Path.Value;
|
||||||
|
var isIRacisFile = path.StartsWith($"/{StaticData.Folder.IRaCISDataFolder}");
|
||||||
|
|
||||||
|
var isDicomFile = path.Contains($"{StaticData.Folder.DicomFolder}");
|
||||||
|
|
||||||
|
var isFind = false;
|
||||||
|
if (isIRacisFile)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
if (isDicomFile)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 如果所有磁盘都不存在所请求的文件,则将请求传递给下一个中间件组件。
|
||||||
|
await _next.Invoke(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ServeFileAsync(HttpContext context, IFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
var response = context.Response;
|
||||||
|
response.ContentType = GetContentType(fileInfo.PhysicalPath);
|
||||||
|
|
||||||
|
using (var fileStream = fileInfo.CreateReadStream())
|
||||||
|
{
|
||||||
|
await fileStream.CopyToAsync(response.Body);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string[] GetDisks()
|
||||||
|
{
|
||||||
|
// 获取系统中所有可用的磁盘
|
||||||
|
return DriveInfo.GetDrives()
|
||||||
|
.Where(d => d.IsReady && d.DriveType == DriveType.Fixed)
|
||||||
|
.Select(d => d.RootDirectory.FullName)
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetContentType(string path)
|
||||||
|
{
|
||||||
|
var provider = new FileExtensionContentTypeProvider();
|
||||||
|
if (!provider.TryGetContentType(path, out var contentType))
|
||||||
|
{
|
||||||
|
contentType = "application/octet-stream";
|
||||||
|
}
|
||||||
|
|
||||||
|
return contentType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// await Next.Invoke(context);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private string[] GetDisks()
|
|
||||||
// {
|
|
||||||
// // 获取系统中所有可用的磁盘
|
|
||||||
// return DriveInfo.GetDrives()
|
|
||||||
// .Where(d => d.IsReady && d.DriveType == DriveType.Fixed)
|
|
||||||
// .Select(d => d.RootDirectory.FullName)
|
|
||||||
// .ToArray();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue