fix: 文件名增加时间戳,避免文件被覆盖

This commit is contained in:
cjy 2026-03-03 15:44:06 +08:00
parent e90d298f98
commit 0515d2ab03

View File

@ -1315,9 +1315,11 @@ func checkAndReuploadImageForReport(imageUrl string) (string, error) {
}
// generateReportFileName 生成竞品报告PDF文件名
// 如果有标题则使用标题,否则使用默认格式(日期+老师+时间戳)
// 始终使用标题+时间戳格式避免文件名冲突导致OSS覆盖
func generateReportFileName(title, artistName string) string {
// 如果有标题,使用标题命名
timestamp := time.Now().UnixMicro()
// 如果有标题,使用标题+时间戳
if title != "" {
// 替换标题中的特殊字符为合法字符
fileName := strings.NewReplacer(
@ -1332,15 +1334,15 @@ func generateReportFileName(title, artistName string) string {
"|", "",
" ", "_",
).Replace(title)
// 限制文件名长度,避免过长
if len(fileName) > 100 {
fileName = fileName[:100]
// 限制文件名长度,避免过长(预留时间戳的空间)
if len(fileName) > 80 {
fileName = fileName[:80]
}
return fileName
return fmt.Sprintf("%s_%d", fileName, timestamp)
}
// 没有标题时使用默认格式
today := time.Now().Format("20060102")
timestamp := time.Now().UnixMicro()
return fmt.Sprintf("%s%s老师的竞品报告%d", today, artistName, timestamp)
}