Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.
TypeScript agent-skillscodex-clideskop-appdubbingimage-generationlocalizationskillsttsvideo-editingvideo-generationvideo-transcriptionvideo-translation
feat: better semantic task id
沈浩e71558d0c6ae
diff --git a/internal/service/subtitle_service.go b/internal/service/subtitle_service.goindex b3b57ee5..2853f0d8 100644--- a/internal/service/subtitle_service.go+++ b/internal/service/subtitle_service.go@@ -33,7 +33,7 @@ func (s Service) StartSubtitleTask(req dto.StartVideoSubtitleTaskReq) (*dto.Star}// 生成任务idseperates := strings.Split(req.Url, "/")- taskId := fmt.Sprintf("%s_%s", util.KeepOnlyAlphanumeric(string([]rune(strings.ReplaceAll(seperates[len(seperates)-1], " ", ""))[:16])), util.GenerateRandStringWithUpperLowerNum(4))+ taskId := fmt.Sprintf("%s_%s", util.SanitizePathName(string([]rune(strings.ReplaceAll(seperates[len(seperates)-1], " ", ""))[:16])), util.GenerateRandStringWithUpperLowerNum(4))// 构造任务所需参数var resultType types.SubtitleResultType// 根据入参选项确定要返回的字幕类型diff --git a/pkg/util/base.go b/pkg/util/base.goindex 3f688abc..01245228 100644--- a/pkg/util/base.go+++ b/pkg/util/base.go@@ -11,6 +11,7 @@ import ("os""path/filepath""regexp"+ "runtime""strconv""strings""unicode"@@ -185,13 +186,38 @@ func CopyFile(src, dst string) error {return destinationFile.Sync()}-// KeepOnlyAlphanumeric 只保留字母(a-zA-Z)和数字(0-9)-func KeepOnlyAlphanumeric(input string) string {- var result []rune- for _, r := range input {- if unicode.IsLetter(r) || unicode.IsNumber(r) {- result = append(result, r)- }+// SanitizePathName 清理字符串,使其成为合法路径名+func SanitizePathName(name string) string {+ var illegalChars *regexp.Regexp+ if runtime.GOOS == "windows" {+ // Windows 特殊字符+ illegalChars = regexp.MustCompile(`[<>:"/\\|?*\x00-\x1F]`)+ } else {+ // POSIX 系统:只禁用 / 和空字节+ illegalChars = regexp.MustCompile(`[/\x00]`)+ }++ sanitized := illegalChars.ReplaceAllString(name, "_")++ // 去除前后空格+ sanitized = strings.TrimSpace(sanitized)++ // 防止空字符串+ if sanitized == "" {+ sanitized = "unnamed"}- return string(result)++ // 避免 Windows 下的保留文件名+ reserved := map[string]bool{+ "CON": true, "PRN": true, "AUX": true, "NUL": true,+ "COM1": true, "COM2": true, "COM3": true, "COM4": true,+ "LPT1": true, "LPT2": true,+ }++ upper := strings.ToUpper(sanitized)+ if reserved[upper] {+ sanitized = "_" + sanitized+ }++ return sanitized}