Skip to content

Commit

Permalink
Fix plugins init in Configure.AppHost.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Layoric committed Feb 6, 2024
1 parent 40c30d7 commit 4b309be
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions TypeChatExamples/Configure.AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IRequireFeature>().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) {}
Expand All @@ -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<FileSystemVirtualFiles>();
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<IRequireFeature>().Feature}/{ctx.DateSegment}/{DateTime.UtcNow.TimeOfDay.TotalMilliseconds}.{ctx.FileExtension}")
));
}
}

/// <summary>
Expand Down

0 comments on commit 4b309be

Please sign in to comment.