merge: 合并OMC分支

This commit is contained in:
TsMask
2024-07-10 14:18:48 +08:00
parent 17c0011c6b
commit 625ed57a50
260 changed files with 9167 additions and 14857 deletions

View File

@@ -60,9 +60,12 @@ func uploadWhiteList() []string {
// fileName 原始文件名称含后缀logo.png
func generateFileName(fileName string) string {
fileExt := filepath.Ext(fileName)
// 替换掉后缀和特殊字符保留文件名
// 去除后缀
newFileName := regular.Replace(fileName, fileExt, "")
newFileName = regular.Replace(newFileName, `[<>:"\\|?*]+`, "")
// 去除非法字符
newFileName = regular.Replace(newFileName, `[\\/:*?"<>|]`, "")
// 去除空格
newFileName = regular.Replace(newFileName, `\s`, "_")
newFileName = strings.TrimSpace(newFileName)
return fmt.Sprintf("%s_%s%s", newFileName, generate.Code(6), fileExt)
}
@@ -174,13 +177,13 @@ func ReadUploadFileStream(filePath, headerRange string) (map[string]any, error)
"range": "",
"chunkSize": 0,
"fileSize": 0,
"data": nil,
"data": []byte{},
}
// 文件大小
fileSize := getFileSize(fileAsbPath)
if fileSize <= 0 {
return result, nil
return result, fmt.Errorf("file does not exist")
}
result["fileSize"] = fileSize
@@ -309,12 +312,12 @@ func CopyUploadFile(filePath, dst string) error {
}
defer src.Close()
if err := os.MkdirAll(filepath.Dir(dst), 0750); err != nil {
if err := os.MkdirAll(filepath.Dir(dst), 0775); err != nil {
return err
}
// 如果目标文件已经存在,先将目标文件重命名
if _, err := os.Stat(dst); err == nil {
if info, err := os.Stat(dst); err == nil && !info.IsDir() {
ext := filepath.Ext(dst)
name := dst[0 : len(dst)-len(ext)]
newName := fmt.Sprintf("%s-%s%s", name, time.Now().Format("20060102_150405"), ext)