feat: 完成图片生成功能
This commit is contained in:
@@ -984,11 +984,12 @@ public class AiGateWayManager : DomainService
|
||||
var data = await chatService.GenerateContentAsync(modelDescribe, request, cancellationToken);
|
||||
|
||||
//解析json,获取base64字符串
|
||||
var imageBase64 = GeminiGenerateContentAcquirer.GetImageBase64(data);
|
||||
var imageBase64 = GeminiGenerateContentAcquirer.GetImagePrefixBase64(data);
|
||||
|
||||
//远程调用上传接口,将base64转换为URL
|
||||
var httpClient = LazyServiceProvider.LazyGetRequiredService<IHttpClientFactory>().CreateClient();
|
||||
var uploadUrl = $"https://ccnetcore.com/prod-api/ai-hub/ai-image/upload-base64";
|
||||
// var uploadUrl = $"https://ccnetcore.com/prod-api/ai-hub/ai-image/upload-base64";
|
||||
var uploadUrl = $"http://localhost:19001/api/app/ai-image/upload-base64";
|
||||
var content = new StringContent(JsonSerializer.Serialize(imageBase64), Encoding.UTF8, "application/json");
|
||||
var uploadResponse = await httpClient.PostAsync(uploadUrl, content, cancellationToken);
|
||||
uploadResponse.EnsureSuccessStatusCode();
|
||||
@@ -1020,7 +1021,7 @@ public class AiGateWayManager : DomainService
|
||||
}
|
||||
|
||||
//设置存储base64和url
|
||||
imageStoreTask.StoreBase64 = imageBase64;
|
||||
imageStoreTask.StorePrefixBase64 = imageBase64;
|
||||
imageStoreTask.SetSuccess(storeUrl);
|
||||
await _imageStoreTaskRepository.UpdateAsync(imageStoreTask);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user