1- // Licensed to the .NET Foundation under one or more agreements.
1+ // Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the Apache 2.0 License
33// See the LICENSE file in the project root for more information.
44// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
@@ -20,4 +20,39 @@ public static void UseUploaderStaticFiles(this WebApplication app)
2020 RequestPath = "/images/uploader"
2121 } ) ;
2222 }
23+
24+ public static void UseLLMsStaticFiles ( this WebApplication app )
25+ {
26+ var llms = Path . Combine ( app . Environment . WebRootPath , "llms" ) ;
27+ Directory . CreateDirectory ( llms ) ;
28+
29+ app . UseStaticFiles ( new StaticFileOptions
30+ {
31+ FileProvider = new PhysicalFileProvider ( llms ) ,
32+ RequestPath = "/llms" ,
33+ OnPrepareResponse = context =>
34+ {
35+ context . Context . Response . ContentType = "text/plain; charset=utf-8" ;
36+ }
37+ } ) ;
38+
39+ app . MapGet ( "/llms.txt" , async context =>
40+ {
41+ context . Response . Headers . ContentType = "text/plain; charset=utf-8" ;
42+ var filePath = Path . Combine ( app . Environment . WebRootPath , "llms" , "llms.txt" ) ;
43+ if ( File . Exists ( filePath ) )
44+ {
45+ var fileInfo = new FileInfo ( filePath ) ;
46+ context . Response . ContentLength = fileInfo . Length ;
47+
48+ using var fileStream = new FileStream ( filePath , FileMode . Open , FileAccess . Read , FileShare . Read , bufferSize : 4096 , useAsync : true ) ;
49+ await fileStream . CopyToAsync ( context . Response . Body ) ;
50+ return ;
51+ }
52+
53+ var defaultContent = "no llms.txt" ;
54+ context . Response . ContentLength = defaultContent . Length ;
55+ await context . Response . WriteAsync ( defaultContent ) ;
56+ } ) ;
57+ }
2358}
0 commit comments