feat: 优化AI图片存储与访问流程
- 统一图片存储服务地址常量,返回完整可访问URL - 图片上传接口支持匿名访问,并按日期创建存储目录 - ImageStoreTask 移除无用生成图片 Base64 字段,调整大字段存储配置 - 创建图片任务时补充 ModelId 信息 - 优先使用 Authorization 头部,避免覆盖已有认证信息 - 前端补充 Element Plus Descriptions 组件类型声明
This commit is contained in:
@@ -98,7 +98,8 @@ public class AiImageService : ApplicationService
|
||||
ReferenceImagesUrl = new List<string>(),
|
||||
TaskStatus = TaskStatusEnum.Processing,
|
||||
UserId = userId,
|
||||
TokenId = input.TokenId
|
||||
TokenId = input.TokenId,
|
||||
ModelId = input.ModelId
|
||||
};
|
||||
|
||||
await _imageTaskRepository.InsertAsync(task);
|
||||
@@ -146,6 +147,7 @@ public class AiImageService : ApplicationService
|
||||
/// <param name="base64Data">Base64图片数据(包含前缀如 data:image/png;base64,)</param>
|
||||
/// <returns>图片访问URL</returns>
|
||||
[HttpPost("ai-image/upload-base64")]
|
||||
[AllowAnonymous]
|
||||
public async Task<string> UploadBase64ToUrlAsync([FromBody] string base64Data)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(base64Data))
|
||||
@@ -194,22 +196,31 @@ public class AiImageService : ApplicationService
|
||||
throw new UserFriendlyException("Base64格式无效");
|
||||
}
|
||||
|
||||
// 创建存储目录
|
||||
var uploadPath = Path.Combine(_webHostEnvironment.ContentRootPath, "wwwroot", "ai-images");
|
||||
// ==============================
|
||||
// ✅ 按日期创建目录(yyyyMMdd)
|
||||
// ==============================
|
||||
var dateFolder = DateTime.Now.ToString("yyyyMMdd");
|
||||
var uploadPath = Path.Combine(
|
||||
_webHostEnvironment.ContentRootPath,
|
||||
"wwwroot",
|
||||
"ai-images",
|
||||
dateFolder
|
||||
);
|
||||
|
||||
if (!Directory.Exists(uploadPath))
|
||||
{
|
||||
Directory.CreateDirectory(uploadPath);
|
||||
}
|
||||
|
||||
// 生成文件名并保存
|
||||
// 保存文件
|
||||
var fileId = _guidGenerator.Create();
|
||||
var fileName = $"{fileId}{extension}";
|
||||
var filePath = Path.Combine(uploadPath, fileName);
|
||||
|
||||
await File.WriteAllBytesAsync(filePath, imageBytes);
|
||||
|
||||
// 返回访问URL
|
||||
return $"/ai-images/{fileName}";
|
||||
// 返回包含日期目录的访问URL
|
||||
return $"/wwwroot/ai-images/{dateFolder}/{fileName}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user