diff --git a/IRaCIS.Core.API/_PipelineExtensions/IRacisHostFile/MultiDiskStaticFilesMiddleware.cs b/IRaCIS.Core.API/_PipelineExtensions/IRacisHostFile/MultiDiskStaticFilesMiddleware.cs index e5c4ee39d..053b8d48d 100644 --- a/IRaCIS.Core.API/_PipelineExtensions/IRacisHostFile/MultiDiskStaticFilesMiddleware.cs +++ b/IRaCIS.Core.API/_PipelineExtensions/IRacisHostFile/MultiDiskStaticFilesMiddleware.cs @@ -49,20 +49,21 @@ namespace IRaCIS.Core.API var isDicomFile = path.Contains($"{StaticData.Folder.DicomFolder}"); - var defaultFileProvider = new PhysicalFileProvider(FileStoreHelper.GetIRaCISRootPath(_hostingEnv)); - var staticFileOptions = new StaticFileOptions - { - FileProvider = defaultFileProvider, - RequestPath = $"/{StaticData.Folder.IRaCISDataFolder}", - ServeUnknownFileTypes = true, - DefaultContentType = "application/octet-stream" - }; - var defaultRoot = Path.GetPathRoot(iRaCISDefaultDataFolder); //先从默认里面去找 if (isIRacisFile) { + var defaultFileProvider = new PhysicalFileProvider(FileStoreHelper.GetIRaCISRootPath(_hostingEnv)); + + var staticFileOptions = new StaticFileOptions + { + FileProvider = defaultFileProvider, + RequestPath = $"/{StaticData.Folder.IRaCISDataFolder}", + ServeUnknownFileTypes = true, + DefaultContentType = "application/octet-stream" + }; + if (defaultFileProvider.GetFileInfo(context.Request.Path).Exists) { @@ -78,7 +79,14 @@ namespace IRaCIS.Core.API //dicom影像,从多个文件夹尝试,因为会存在切换磁盘 if (isDicomFile) { - var disks = GetDisks().Where(t=>!t.Contains(defaultRoot)); + var defaultRoot = Path.GetPathRoot(iRaCISDefaultDataFolder); + + //除默认部署路径的其他路径 + var disks = DriveInfo.GetDrives() + .Where(d => d.IsReady && d.DriveType == DriveType.Fixed)/*.Where(t => !t.Name.Contains("C") && !t.Name.Contains("c"))*/ + .OrderBy(d => d.AvailableFreeSpace) + .Select(d => d.RootDirectory.FullName) + .ToArray().Where(t=>!t.Contains(defaultRoot)); foreach (var item in disks) @@ -92,13 +100,7 @@ namespace IRaCIS.Core.API var otherFileProvider= new PhysicalFileProvider(otherFileStoreFolder); - var otherStaticFileOptions = new StaticFileOptions - { - FileProvider = otherFileProvider, - RequestPath = $"/{StaticData.Folder.IRaCISDataFolder}", - ServeUnknownFileTypes = true, - DefaultContentType = "application/octet-stream" - }; + if (otherFileProvider.GetFileInfo(context.Request.Path).Exists) { @@ -108,9 +110,20 @@ namespace IRaCIS.Core.API //方式一 await context.Response.SendFileAsync( new PhysicalFileInfo(new FileInfo(actrualPath))); - //方式二 + #region 方式二 报错 otherFileProvider 应该还包含/{StaticData.Folder.IRaCISDataFolder} 这一层级 + //var otherStaticFileOptions = new StaticFileOptions + //{ + // FileProvider = otherFileProvider, + // RequestPath = $"/{StaticData.Folder.IRaCISDataFolder}", + // ServeUnknownFileTypes = true, + // DefaultContentType = "application/octet-stream" + //}; //var staticFileMiddleware = new StaticFileMiddleware(_next, _hostingEnv, Options.Create(otherStaticFileOptions), _loggerFactory); //await staticFileMiddleware.Invoke(context); + #endregion + + + return; } } @@ -123,14 +136,7 @@ namespace IRaCIS.Core.API - private string[] GetDisks() - { - // 获取系统中所有可用的磁盘 - return DriveInfo.GetDrives() - .Where(d => d.IsReady && d.DriveType == DriveType.Fixed).Where(t => !t.Name.Contains("C") && !t.Name.Contains("c")) - .Select(d => d.RootDirectory.FullName) - .ToArray(); - } + //private static string GetContentType(string path)