MCPcopy Create free account
hub / github.com/53AI/53AIHub / generateUniqueFileName

Function generateUniqueFileName

api/controller/wps.go:147–172  ·  view source on GitHub ↗

generateUniqueFileName 生成唯一的文件名,如果重复则添加序号

(eid, libraryID int64, dirPath, fileName, extension string, excludeFileID int64)

Source from the content-addressed store, hash-verified

145
146// generateUniqueFileName 生成唯一的文件名,如果重复则添加序号
147func generateUniqueFileName(eid, libraryID int64, dirPath, fileName, extension string, excludeFileID int64) string {
148 baseName := fileName
149 if extension != "" && !strings.HasSuffix(fileName, extension) {
150 fileName = fileName + extension
151 }
152
153 // 检查是否重复
154 counter := 1
155 for {
156 fullPath := dirPath + "/" + fileName
157 if !strings.HasPrefix(dirPath, "/") {
158 fullPath = "/" + fullPath
159 }
160
161 // 使用现有的GetFileByPath函数检查重复
162 existingFile, err := model.GetFileByPath(eid, libraryID, fullPath)
163 if err != nil || (existingFile != nil && existingFile.ID == excludeFileID) {
164 // 没有找到重复文件或者是同一个文件,可以使用这个文件名
165 return fileName
166 }
167
168 // 有重复文件,添加序号
169 fileName = fmt.Sprintf("%s(%d)%s", baseName, counter, extension)
170 counter++
171 }
172}
173
174// resolveWPSVisibleFileName returns the file name that should be exposed to WPS.
175// It strips internal workspace prefixes such as "output/" so the editor only

Callers 1

executeWPSFileUploadFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected