修改
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using IRaCIS.Core.Application.Helper;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using System.IO;
|
||||
|
||||
namespace IRaCIS.Core.API
|
||||
{
|
||||
public static class IRacisHostFileStore
|
||||
{
|
||||
|
||||
public static void UseIRacisHostStaticFileStore(this IApplicationBuilder app, IWebHostEnvironment _hostEnvironment)
|
||||
{
|
||||
|
||||
var iRaCISDataFolder = FileStoreHelper.GetIRaCISRootDataFolder(_hostEnvironment);
|
||||
|
||||
if (!Directory.Exists(iRaCISDataFolder))
|
||||
{
|
||||
Directory.CreateDirectory(iRaCISDataFolder);
|
||||
}
|
||||
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
FileProvider = new PhysicalFileProvider(iRaCISDataFolder),
|
||||
RequestPath = $"/{StaticData.Folder.IRaCISDataFolder}",
|
||||
ServeUnknownFileTypes = true,
|
||||
DefaultContentType = "application/octet-stream"
|
||||
|
||||
// // Set up custom content types - associating file extension to MIME type
|
||||
//var provider = new FileExtensionContentTypeProvider();
|
||||
// // Add new mappings
|
||||
// provider.Mappings[".myapp"] = "application/x-msdownload";
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.StaticFiles;
|
||||
using Microsoft.Extensions.FileProviders.Physical;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.IO;
|
||||
|
||||
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)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// await base.InvokeAsync(context);
|
||||
// }
|
||||
// catch (FileNotFoundException)
|
||||
// {
|
||||
// var disks = GetDisks();
|
||||
|
||||
// foreach (var disk in disks)
|
||||
// {
|
||||
// var fileInfo = new PhysicalFileInfo(new FileInfo(Path.Combine(disk, Options.RequestPath.Value)));
|
||||
// if (fileInfo.Exists)
|
||||
// {
|
||||
// await SendFileAsync(context, fileInfo);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
// await Next.Invoke(context);
|
||||
// }
|
||||
// }
|
||||
|
||||
// private string[] GetDisks()
|
||||
// {
|
||||
// // 获取系统中所有可用的磁盘
|
||||
// return DriveInfo.GetDrives()
|
||||
// .Where(d => d.IsReady && d.DriveType == DriveType.Fixed)
|
||||
// .Select(d => d.RootDirectory.FullName)
|
||||
// .ToArray();
|
||||
// }
|
||||
//}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user