using VideoAnalysisCore.Common; using Microsoft.OpenApi.Models; using VideoAnalysisCore.AICore.SherpaOnnx; using Mapster; using VideoAnalysisCore.AICore.GPT; using VideoAnalysisCore.AICore.GPT.ChatGPT; using Microsoft.Extensions.FileProviders; using VideoAnalysisCore.AICore.GPT.DeepSeek; using Microsoft.Extensions.DependencyInjection; using VideoAnalysisCore.Common.Expand; using Learn.VideoAnalysis.Expand; using Microsoft.AspNetCore.Mvc.Formatters; using System.Security.Cryptography; using System.Diagnostics; using VideoAnalysisCore.AICore.FFMPGE; using System.Text.Encodings.Web; using System.Text.Unicode; using System.Text.Json; namespace Learn.VideoAnalysis { public class Program { public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); //设置接口请求体最大100m builder.WebHost.ConfigureKestrel(serverOptions => { serverOptions.Limits.MaxRequestBodySize = 100_000_000; // 100MB }); builder.Services.AddLogging(loggingBuilder => { loggingBuilder.ClearProviders(); // 清除默认的日志提供程序 loggingBuilder.AddConsole(); // 添加控制台日志提供程序 loggingBuilder.SetMinimumLevel(LogLevel.Warning); // 设置最小日志级别为 Warning }); //初始化 插件 builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerExpand("AI视频分析"); //绑定 appsetting 配置 builder.Configuration.AddAppConfig(args); builder.Services.AddPermissionAuthentication(); builder.Services.AddSqlSugarExpand(); builder.Services.AddRedisExpand(); builder.Services.AddSimpleTexOcrClient(); builder.Services.AddDownloadFileExpand(); builder.Services.AddFFMPGEExpand(); builder.Services.AddAlibabaCloudVod(); builder.Services.AddAliyunOSS(); builder.Services.AddSenseVoiceExpand(); //builder.Services.AddSpeakerAI(); builder.Services.AddCoravel(); //SenseVoice.Init(); //异常过滤器 builder.Services.AddControllersWithViews(options => { options.Filters.Add(typeof(ExceptionFilter)); }); builder.Services.AddControllers() .AddJsonOptions(options => { options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);//中文转换时不使用Unicode options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;// 默认小驼峰 null 大驼峰 options.JsonSerializerOptions.PropertyNameCaseInsensitive = true; }); builder.Services.AddScoped(sp => { var httpContext = sp.GetRequiredService().HttpContext; if (httpContext != null) { return new HttpClient { BaseAddress = new Uri(httpContext.Request.Scheme + "://" + httpContext.Request.Host) }; } return new HttpClient(); }); builder.Services.AddMapster(); builder.Services.AddCorsExpand(); builder.Services.AddHttpClient(); builder.Services.AddHttpContextAccessor(); builder.Services.AddGPTService(); builder.Services.AddTaskSubscribe(); var app = builder.Build(); AppCommon.Services = app.Services; app.UseMiddleware("Swagger"); // Configure the HTTP request pipeline. _ = app.Services.GetRequiredService(); app.UseSwagger(); app.UseSwaggerUI(); app.UseExceptionHandler("/Error"); //添加wwwroot 静态目录 app.UseStaticFiles(); //添加 自定义 静态目录 app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(AppCommon.TaskCachedFile), RequestPath = "/video", }); app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(AppCommon.WebUIFile), RequestPath = "/ui", }); app.UseAntiforgery(); app.MapControllers(); //自定义 应用 app.UseCorsExpand(); app.UseSqlSugarExpand(); app.UseCoravelExpand(); app.Run(); } } }