Merge branch 'master' of https://gitea.nxsir.cn/nanxun/IM_NEW
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
|
||||
using IM.InitCommon;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
|
||||
namespace FileService.WebApi
|
||||
{
|
||||
@@ -29,10 +30,38 @@ namespace FileService.WebApi
|
||||
|
||||
app.UseAppDefault();
|
||||
|
||||
// 仅 FileService 暴露公开桶目录为静态直链,不动共享 UseAppDefault
|
||||
UsePublicStaticFiles(app);
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
|
||||
private static void UsePublicStaticFiles(WebApplication app)
|
||||
{
|
||||
var storage = app.Configuration.GetSection("StorageOptions").Get<StorageOptions>();
|
||||
if (storage?.Providers == null ||
|
||||
!storage.Providers.TryGetValue(storage.DefaultProviderCode, out var provider))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(provider.LocalRootPath) || string.IsNullOrEmpty(provider.PublicBucket))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var publicPath = Path.Combine(provider.LocalRootPath, provider.PublicBucket);
|
||||
Directory.CreateDirectory(publicPath);
|
||||
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
FileProvider = new PhysicalFileProvider(publicPath),
|
||||
RequestPath = "/static",
|
||||
OnPrepareResponse = ctx =>
|
||||
ctx.Context.Response.Headers["Cache-Control"] = "public,max-age=2592000"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user