2025-09-07 01:34:25 +08:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using Volo.Abp.Application.Services;
|
|
|
|
|
|
using Volo.Abp.Users;
|
|
|
|
|
|
using Yi.Framework.AiHub.Application.Contracts.Dtos.FileMaster;
|
|
|
|
|
|
using Yi.Framework.AiHub.Domain.Managers;
|
|
|
|
|
|
using Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Yi.Framework.AiHub.Application.Services.FileMaster;
|
|
|
|
|
|
|
|
|
|
|
|
public class FileMasterService : ApplicationService
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
|
|
private readonly AiGateWayManager _aiGateWayManager;
|
|
|
|
|
|
private readonly AiBlacklistManager _aiBlacklistManager;
|
|
|
|
|
|
|
2025-09-13 21:19:54 +08:00
|
|
|
|
public FileMasterService(IHttpContextAccessor httpContextAccessor, AiGateWayManager aiGateWayManager,
|
|
|
|
|
|
AiBlacklistManager aiBlacklistManager)
|
2025-09-07 01:34:25 +08:00
|
|
|
|
{
|
|
|
|
|
|
_httpContextAccessor = httpContextAccessor;
|
|
|
|
|
|
_aiGateWayManager = aiGateWayManager;
|
|
|
|
|
|
_aiBlacklistManager = aiBlacklistManager;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 校验下一步
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
2025-09-07 01:34:52 +08:00
|
|
|
|
[HttpPost("FileMaster/VerifyNext")]
|
2025-09-07 01:34:25 +08:00
|
|
|
|
public Task<string> VerifyNextAsync(VerifyNextInput input)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!CurrentUser.IsAuthenticated)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (input.DirectoryCount + input.FileCount >= 20)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new UserFriendlyException("未登录用户,文件夹与文件数量不能大于20个,请登录后解锁全部功能");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-09-13 21:19:54 +08:00
|
|
|
|
if (input.DirectoryCount + input.FileCount >= 100)
|
2025-09-07 01:34:25 +08:00
|
|
|
|
{
|
2025-09-13 21:19:54 +08:00
|
|
|
|
throw new UserFriendlyException("为防止无限制暴力使用,当前文件整理大师Vip最多支持200文件与文件夹数量");
|
2025-09-07 01:34:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Task.FromResult("success");
|
|
|
|
|
|
}
|
2025-09-13 21:19:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-09-07 01:34:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 对话
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
|
[HttpPost("FileMaster/chat/completions")]
|
|
|
|
|
|
public async Task ChatCompletionsAsync([FromBody] ThorChatCompletionsRequest input,
|
|
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CurrentUser.IsAuthenticated)
|
|
|
|
|
|
{
|
|
|
|
|
|
input.Model = "gpt-5-chat";
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-09-13 21:19:54 +08:00
|
|
|
|
input.Model = "gpt-5-chat";
|
2025-09-07 01:34:25 +08:00
|
|
|
|
}
|
2025-09-13 21:19:54 +08:00
|
|
|
|
|
2025-09-07 01:34:25 +08:00
|
|
|
|
Guid? userId = CurrentUser.IsAuthenticated ? CurrentUser.GetId() : null;
|
|
|
|
|
|
if (userId is not null)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _aiBlacklistManager.VerifiyAiBlacklist(userId.Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//ai网关代理httpcontext
|
|
|
|
|
|
if (input.Stream == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _aiGateWayManager.CompleteChatStreamForStatisticsAsync(_httpContextAccessor.HttpContext, input,
|
|
|
|
|
|
userId, null, cancellationToken);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
await _aiGateWayManager.CompleteChatForStatisticsAsync(_httpContextAccessor.HttpContext, input, userId,
|
|
|
|
|
|
null,
|
|
|
|
|
|
cancellationToken);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|