From 4b309beeab096f407f5b92ef25b66f46524a4716 Mon Sep 17 00:00:00 2001 From: Darren Reid Date: Tue, 6 Feb 2024 18:15:33 +1100 Subject: [PATCH] Fix plugins init in Configure.AppHost.cs --- TypeChatExamples/Configure.AppHost.cs | 36 +++++++++++++-------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/TypeChatExamples/Configure.AppHost.cs b/TypeChatExamples/Configure.AppHost.cs index c3cdd17..3fb6e33 100644 --- a/TypeChatExamples/Configure.AppHost.cs +++ b/TypeChatExamples/Configure.AppHost.cs @@ -60,6 +60,23 @@ public void Configure(IWebHostBuilder builder) => builder appConfig.NodePath ??= ProcessUtils.FindExePath("node") ?? throw new Exception("Could not resolve path to node"); appConfig.FfmpegPath ??= ProcessUtils.FindExePath("ffmpeg"); } + + var wwwrootVfs = new FileSystemVirtualFiles(context.HostingEnvironment.ContentRootPath.CombineWith("wwwroot")); + var vfs = new FileSystemVirtualFiles(context.HostingEnvironment.ContentRootPath); + services.AddPlugin(new FilesUploadFeature( + new UploadLocation("products", wwwrootVfs, allowExtensions:FileExt.WebImages, + resolvePath: ctx => $"/products/{ctx.FileName}"), + new UploadLocation("recordings", vfs, allowExtensions:FileExt.WebAudios, writeAccessRole: RoleNames.AllowAnon, + maxFileBytes: 1024 * 1024, + transformFile: ctx => ConvertAudioToWebM(ctx.File), + resolvePath: ctx => $"/recordings/{ctx.GetDto().Feature}/{ctx.DateSegment}/{DateTime.UtcNow.TimeOfDay.TotalMilliseconds}.{ctx.FileExtension}") + )); + + services.AddPlugin(new CorsFeature(new[] { + "http://localhost:5173", //vite dev + }, allowCredentials:true)); + + services.AddPlugin(new ProfilingFeature()); }); public AppHost() : base("TypeChat Examples", typeof(GptServices).Assembly) {} @@ -68,25 +85,6 @@ public override void Configure(Container container) { SetConfig(new HostConfig { }); - - Plugins.Add(new CorsFeature(new[] { - "http://localhost:5173", //vite dev - }, allowCredentials:true)); - - Plugins.Add(new ProfilingFeature()); - - if (!AppTasks.IsRunAsAppTask()) - { - var wwwrootVfs = GetVirtualFileSource(); - Plugins.Add(new FilesUploadFeature( - new UploadLocation("products", wwwrootVfs, allowExtensions:FileExt.WebImages, - resolvePath: ctx => $"/products/{ctx.FileName}"), - new UploadLocation("recordings", VirtualFiles, allowExtensions:FileExt.WebAudios, writeAccessRole: RoleNames.AllowAnon, - maxFileBytes: 1024 * 1024, - transformFile: ctx => ConvertAudioToWebM(ctx.File), - resolvePath: ctx => $"/recordings/{ctx.GetDto().Feature}/{ctx.DateSegment}/{DateTime.UtcNow.TimeOfDay.TotalMilliseconds}.{ctx.FileExtension}") - )); - } } ///