This commit is contained in:
2026-08-31 14:42:22 +08:00
72 changed files with 2479 additions and 168 deletions
+29
View File
@@ -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"
});
}
}
}