Learn.VideoAnalysis/VideoAnalysis/Program.cs

146 lines
5.2 KiB
C#

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;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Hosting.Server;
namespace Learn.VideoAnalysis
{
public class Program
{
public static void Main(string[] args)
{
//交互式环境选择函数
AppConfigExpand.SelectEnvironment(ref 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
});
//绑定 appsetting 配置
builder.AddAppConfig(args);
//初始化 插件
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerExpand("AI视频分析");
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.AddFunASRNanoExpand();
builder.Services.AddSherpaVadExpand();
//builder.Services.AddSpeakerAI();
//定时任务
builder.Services.AddCoravel();
//异常过滤器
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<IHttpContextAccessor>().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<BasicAuthMiddleware>("Swagger");
// Configure the HTTP request pipeline.
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.UseServiceSystem(() =>
{
//开启redis队列服务
_ = AppCommon.Services.GetRequiredService<RedisInit>();
});
app.Run();
}
}
}