切换存储
This commit is contained in:
+22
-7
@@ -11,6 +11,7 @@ using Microsoft.Extensions.Hosting.Internal;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.VisualBasic;
|
||||
using SharpCompress.Common;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -23,16 +24,14 @@ namespace IRaCIS.Core.API
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly IWebHostEnvironment _hostingEnv;
|
||||
private readonly StaticFileOptions _options;
|
||||
private readonly ILoggerFactory _loggerFactory;
|
||||
|
||||
private string iRaCISDefaultDataFolder = string.Empty;
|
||||
|
||||
public MultiDiskStaticFilesMiddleware(RequestDelegate next, IWebHostEnvironment hostingEnv, StaticFileOptions options, ILoggerFactory loggerFactory)
|
||||
public MultiDiskStaticFilesMiddleware(RequestDelegate next, IWebHostEnvironment hostingEnv, ILoggerFactory loggerFactory)
|
||||
{
|
||||
_next = next;
|
||||
_hostingEnv = hostingEnv;
|
||||
_options = options;
|
||||
_loggerFactory = loggerFactory;
|
||||
|
||||
iRaCISDefaultDataFolder = FileStoreHelper.GetIRaCISRootDataFolder(_hostingEnv);
|
||||
@@ -66,8 +65,12 @@ namespace IRaCIS.Core.API
|
||||
{
|
||||
if (defaultFileProvider.GetFileInfo(context.Request.Path).Exists)
|
||||
{
|
||||
var staticFileMiddleware = new StaticFileMiddleware(_next, _hostingEnv, Options.Create(staticFileOptions), _loggerFactory);
|
||||
await staticFileMiddleware.Invoke(context);
|
||||
//var staticFileMiddleware = new StaticFileMiddleware(_next, _hostingEnv, Options.Create(staticFileOptions), _loggerFactory);
|
||||
//await staticFileMiddleware.Invoke(context);
|
||||
|
||||
var actrualPath = defaultFileProvider.GetFileInfo(context.Request.Path).PhysicalPath;
|
||||
|
||||
await context.Response.SendFileAsync(new PhysicalFileInfo(new FileInfo(actrualPath)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -82,6 +85,11 @@ namespace IRaCIS.Core.API
|
||||
foreach (var item in disks)
|
||||
{
|
||||
var otherFileStoreFolder = Path.Combine(item, _hostingEnv.EnvironmentName);
|
||||
|
||||
if (!Directory.Exists(otherFileStoreFolder))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var otherFileProvider= new PhysicalFileProvider(otherFileStoreFolder);
|
||||
|
||||
@@ -95,8 +103,15 @@ namespace IRaCIS.Core.API
|
||||
|
||||
if (otherFileProvider.GetFileInfo(context.Request.Path).Exists)
|
||||
{
|
||||
var staticFileMiddleware = new StaticFileMiddleware(_next, _hostingEnv, Options.Create(staticFileOptions), _loggerFactory);
|
||||
await staticFileMiddleware.Invoke(context);
|
||||
|
||||
var actrualPath = otherFileProvider.GetFileInfo(context.Request.Path).PhysicalPath;
|
||||
|
||||
//方式一
|
||||
await context.Response.SendFileAsync( new PhysicalFileInfo(new FileInfo(actrualPath)));
|
||||
|
||||
//方式二
|
||||
//var staticFileMiddleware = new StaticFileMiddleware(_next, _hostingEnv, Options.Create(otherStaticFileOptions), _loggerFactory);
|
||||
//await staticFileMiddleware.Invoke(context);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user