feat: 完成openapi改造
This commit is contained in:
@@ -23,7 +23,7 @@ public class AiMessageManager : DomainService
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task CreateSystemMessageAsync(Guid userId, Guid sessionId, MessageInputDto input)
|
||||
public async Task CreateSystemMessageAsync(Guid userId, Guid? sessionId, MessageInputDto input)
|
||||
{
|
||||
input.Role = "system";
|
||||
var message = new MessageAggregateRoot(userId, sessionId, input.Content, input.Role, input.ModelId,input.TokenUsage);
|
||||
@@ -37,7 +37,7 @@ public class AiMessageManager : DomainService
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task CreateUserMessageAsync(Guid userId, Guid sessionId, MessageInputDto input)
|
||||
public async Task CreateUserMessageAsync(Guid userId, Guid? sessionId, MessageInputDto input)
|
||||
{
|
||||
input.Role = "user";
|
||||
var message = new MessageAggregateRoot(userId, sessionId, input.Content, input.Role, input.ModelId,input.TokenUsage);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
using Volo.Abp.Domain.Services;
|
||||
using Volo.Abp.Users;
|
||||
using Yi.Framework.AiHub.Domain.Entities.OpenApi;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.AiHub.Domain.Managers;
|
||||
|
||||
public class TokenManager : DomainService
|
||||
{
|
||||
private readonly ISqlSugarRepository<TokenAggregateRoot> _tokenRepository;
|
||||
|
||||
public TokenManager(ISqlSugarRepository<TokenAggregateRoot> tokenRepository)
|
||||
{
|
||||
_tokenRepository = tokenRepository;
|
||||
}
|
||||
|
||||
public async Task<string?> GetAsync(Guid userId)
|
||||
{
|
||||
var entity = await _tokenRepository._DbQueryable.FirstAsync(x => x.UserId == userId);
|
||||
if (entity is not null)
|
||||
{
|
||||
return entity.Token;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CreateAsync(Guid userId)
|
||||
{
|
||||
var entity = await _tokenRepository._DbQueryable.FirstAsync(x => x.UserId == userId);
|
||||
if (entity is not null)
|
||||
{
|
||||
entity.ResetToken();
|
||||
await _tokenRepository.UpdateAsync(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
var token = new TokenAggregateRoot(userId);
|
||||
await _tokenRepository.InsertAsync(token);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Guid> GetUserIdAsync(string? token)
|
||||
{
|
||||
if (token is null)
|
||||
{
|
||||
throw new UserFriendlyException("当前请求未包含token", "401");
|
||||
}
|
||||
|
||||
if (token.StartsWith("yi-"))
|
||||
{
|
||||
var entity = await _tokenRepository._DbQueryable.Where(x => x.Token == token).FirstAsync();
|
||||
if (entity is null)
|
||||
{
|
||||
throw new UserFriendlyException("当前请求token无效", "401");
|
||||
}
|
||||
|
||||
return entity.UserId;
|
||||
}
|
||||
throw new UserFriendlyException("当前请求token非法", "401");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user