feat: 完成图片生成功能

This commit is contained in:
ccnetcore
2026-01-02 19:26:09 +08:00
parent 3f53eb14ab
commit 560a76558a
14 changed files with 251 additions and 134 deletions

View File

@@ -21,6 +21,11 @@ public class TokenValidationResult
/// Token Id
/// </summary>
public Guid TokenId { get; set; }
/// <summary>
/// token
/// </summary>
public string Token { get; set; }
}
public class TokenManager : DomainService
@@ -39,25 +44,36 @@ public class TokenManager : DomainService
/// <summary>
/// 验证Token并返回用户Id和TokenId
/// </summary>
/// <param name="token">Token密钥</param>
/// <param name="tokenOrId">Token密钥或者TokenId</param>
/// <param name="modelId">模型Id用于判断是否是尊享模型需要检查额度</param>
/// <returns>Token验证结果</returns>
public async Task<TokenValidationResult> ValidateTokenAsync(string? token, string? modelId = null)
public async Task<TokenValidationResult> ValidateTokenAsync(object tokenOrId, string? modelId = null)
{
if (token is null)
if (tokenOrId is null)
{
throw new UserFriendlyException("当前请求未包含token", "401");
}
if (!token.StartsWith("yi-"))
TokenAggregateRoot entity;
if (tokenOrId is Guid tokenId)
{
throw new UserFriendlyException("当前请求token非法", "401");
entity = await _tokenRepository._DbQueryable
.Where(x => x.Id == tokenId)
.FirstAsync();
}
var entity = await _tokenRepository._DbQueryable
.Where(x => x.Token == token)
.FirstAsync();
else
{
var tokenStr = tokenOrId.ToString();
if (!tokenStr.StartsWith("yi-"))
{
throw new UserFriendlyException("当前请求token非法", "401");
}
entity = await _tokenRepository._DbQueryable
.Where(x => x.Token == tokenStr)
.FirstAsync();
}
if (entity is null)
{
throw new UserFriendlyException("当前请求token无效", "401");
@@ -90,7 +106,8 @@ public class TokenManager : DomainService
return new TokenValidationResult
{
UserId = entity.UserId,
TokenId = entity.Id
TokenId = entity.Id,
Token = entity.Token
};
}