feat: 新增海外站点流量限制和CORS配置优化

- 新增yxai.chat域名到CORS白名单
- 为海外站点yxai.chat添加大流量接口访问限制
- 修复Azure OpenAI图像生成服务默认尺寸设置
This commit is contained in:
chenchun
2025-08-14 15:14:30 +08:00
parent 9d4cc802e9
commit 2fd7f88f04
3 changed files with 14 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ public class OpenApiService : ApplicationService
private readonly AiGateWayManager _aiGateWayManager; private readonly AiGateWayManager _aiGateWayManager;
private readonly ISqlSugarRepository<AiModelEntity> _aiModelRepository; private readonly ISqlSugarRepository<AiModelEntity> _aiModelRepository;
private readonly AiBlacklistManager _aiBlacklistManager; private readonly AiBlacklistManager _aiBlacklistManager;
public OpenApiService(IHttpContextAccessor httpContextAccessor, ILogger<OpenApiService> logger, public OpenApiService(IHttpContextAccessor httpContextAccessor, ILogger<OpenApiService> logger,
TokenManager tokenManager, AiGateWayManager aiGateWayManager, TokenManager tokenManager, AiGateWayManager aiGateWayManager,
ISqlSugarRepository<AiModelEntity> aiModelRepository, AiBlacklistManager aiBlacklistManager) ISqlSugarRepository<AiModelEntity> aiModelRepository, AiBlacklistManager aiBlacklistManager)
@@ -69,6 +70,7 @@ public class OpenApiService : ApplicationService
public async Task ImagesGenerationsAsync([FromBody] ImageCreateRequest input, CancellationToken cancellationToken) public async Task ImagesGenerationsAsync([FromBody] ImageCreateRequest input, CancellationToken cancellationToken)
{ {
var httpContext = this._httpContextAccessor.HttpContext; var httpContext = this._httpContextAccessor.HttpContext;
Intercept(httpContext);
var userId = await _tokenManager.GetUserIdAsync(GetTokenByHttpContext(httpContext)); var userId = await _tokenManager.GetUserIdAsync(GetTokenByHttpContext(httpContext));
await _aiBlacklistManager.VerifiyAiBlacklist(userId); await _aiBlacklistManager.VerifiyAiBlacklist(userId);
await _aiGateWayManager.CreateImageForStatisticsAsync(httpContext, userId, null, input); await _aiGateWayManager.CreateImageForStatisticsAsync(httpContext, userId, null, input);
@@ -83,6 +85,7 @@ public class OpenApiService : ApplicationService
public async Task EmbeddingAsync([FromBody] ThorEmbeddingInput input, CancellationToken cancellationToken) public async Task EmbeddingAsync([FromBody] ThorEmbeddingInput input, CancellationToken cancellationToken)
{ {
var httpContext = this._httpContextAccessor.HttpContext; var httpContext = this._httpContextAccessor.HttpContext;
Intercept(httpContext);
var userId = await _tokenManager.GetUserIdAsync(GetTokenByHttpContext(httpContext)); var userId = await _tokenManager.GetUserIdAsync(GetTokenByHttpContext(httpContext));
await _aiBlacklistManager.VerifiyAiBlacklist(userId); await _aiBlacklistManager.VerifiyAiBlacklist(userId);
await _aiGateWayManager.EmbeddingForStatisticsAsync(httpContext, userId, null, input); await _aiGateWayManager.EmbeddingForStatisticsAsync(httpContext, userId, null, input);
@@ -127,4 +130,12 @@ public class OpenApiService : ApplicationService
return null; return null;
} }
private void Intercept(HttpContext httpContext)
{
if (httpContext.Request.Host.Value == "yxai.chat")
{
throw new UserFriendlyException("当前海外站点不支持大流量接口请使用转发站点https://ai.ccnetcore.com");
}
}
} }

View File

@@ -13,7 +13,7 @@ public class AzureOpenAIServiceImageService : IImageService
var createClient = AzureOpenAIFactory.CreateClient(options); var createClient = AzureOpenAIFactory.CreateClient(options);
var client = createClient.GetImageClient(imageCreate.Model); var client = createClient.GetImageClient(imageCreate.Model);
imageCreate.Size??="1024x1024";
// 将size字符串拆分为宽度和高度 // 将size字符串拆分为宽度和高度
var size = imageCreate.Size.Split('x'); var size = imageCreate.Size.Split('x');
if (size.Length != 2) if (size.Length != 2)

View File

@@ -21,7 +21,7 @@
//应用启动 //应用启动
"App": { "App": {
"SelfUrl": "http://*:19001", "SelfUrl": "http://*:19001",
"CorsOrigins": "http://localhost:19001;http://localhost:18000;vscode-file://vscode-app;https://web.chatboxai.app;capacitor://localhost;http://codegeex" "CorsOrigins": "http://localhost:19001;http://localhost:18000;vscode-file://vscode-app;https://web.chatboxai.app;capacitor://localhost;http://codegeex;https://yxai.chat"
}, },
//配置 //配置
"Settings": { "Settings": {