refactor: GIF 单独归类、跨文件系统复制回退与异常处理优化

This commit is contained in:
2025-03-12 21:01:04 +08:00
parent 9ed579d04e
commit 0ebd84d3fe
6 changed files with 83 additions and 14 deletions
+1 -2
View File
@@ -47,8 +47,7 @@ func ReadBmpImage(filePath string) (error, int32, int32) {
// Check if it's a valid BMP file by verifying the file type.
if string(fileHeader.FileType[:]) != "BM" {
fmt.Printf("=== Not a valid BMP file: %v\n", err)
return err, 0, 0
return fmt.Errorf("not a valid BMP file: file type is %q, expected \"BM\"", string(fileHeader.FileType[:])), 0, 0
}
// Read the info header.
+6 -1
View File
@@ -34,7 +34,12 @@ func doReadFileMimeInfo() {
bar.SetNoticeColor(goPrint.FontColor.Red)
for _, currentPath := range vars.GlobalFilePathList {
// mime
vars.GlobalFilePath2MimeInfoMap[currentPath] = util.ReadFileMimeInfo(currentPath).String()
mt := util.ReadFileMimeInfo(currentPath)
if mt != nil {
vars.GlobalFilePath2MimeInfoMap[currentPath] = mt.String()
} else {
vars.GlobalFilePath2MimeInfoMap[currentPath] = ""
}
count = count + 1
bar.PrintBar(util.CalcPercentage(count, total))
}
+12 -1
View File
@@ -114,6 +114,7 @@ func doPickImageFile(uid string, rootDir string, imagePath2WidthHeightMap map[st
moveHorizontalImage(rootDir, uid)
moveVerticalImage(rootDir, uid)
moveSquareImage(rootDir, uid)
moveGifImage(rootDir, uid)
}
// 统一处理gif
@@ -255,7 +256,7 @@ func handleSquareImage(currentImagePath string, width int) {
vars.ImageSquare8KList = append(vars.ImageSquare8KList, currentImagePath)
} else if width < 10000 {
vars.ImageSquare9KList = append(vars.ImageSquare9KList, currentImagePath)
} else if width > 10000 {
} else if width >= 10000 {
vars.ImageSquareHKList = append(vars.ImageSquareHKList, currentImagePath)
}
}
@@ -498,3 +499,13 @@ func moveSquareImage(rootDir string, uid string) {
util.DoMoveFileToDir(vars.ImageSquareHKList, imageDirPath)
}
}
// 移动gif图片
func moveGifImage(rootDir string, uid string) {
if len(vars.ImageGifList) > 0 {
pathSeparator := string(os.PathSeparator)
imageDirPath := rootDir + pathSeparator + uid + "-图片_GIF"
util.CreateDir(imageDirPath)
util.DoMoveFileToDir(vars.ImageGifList, imageDirPath)
}
}
+23 -2
View File
@@ -102,6 +102,7 @@ func doPickVideoFile(rootDir string, videoPath2WidthHeightMap map[string]string)
moveHorizontalVideo(uid, rootDir)
moveVerticalVideo(uid, rootDir)
moveSquareVideo(uid, rootDir)
moveGifVideo(uid, rootDir)
}
// 移动垂直视频
@@ -324,6 +325,26 @@ func moveSquareVideo(uid string, rootDir string) {
}
}
// 移动gif视频
func moveGifVideo(uid string, rootDir string) {
pathSeparator := string(os.PathSeparator)
if len(vars.VideoHorizontalGifList) > 0 {
videoDirPath := rootDir + pathSeparator + uid + "-视频_横屏_GIF"
util.CreateDir(videoDirPath)
util.DoMoveFileToDir(vars.VideoHorizontalGifList, videoDirPath)
}
if len(vars.VideoVerticalGifList) > 0 {
videoDirPath := rootDir + pathSeparator + uid + "-视频_竖屏_GIF"
util.CreateDir(videoDirPath)
util.DoMoveFileToDir(vars.VideoVerticalGifList, videoDirPath)
}
if len(vars.VideoSquareGifList) > 0 {
videoDirPath := rootDir + pathSeparator + uid + "-视频_等比_GIF"
util.CreateDir(videoDirPath)
util.DoMoveFileToDir(vars.VideoSquareGifList, videoDirPath)
}
}
// 移动普通视频
func moveNormalVideo(uid string, rootDir string) {
pathSeparator := string(os.PathSeparator)
@@ -370,7 +391,7 @@ func handleVerticalVideo(currentVideoPath string, height int, suffix string) {
vars.VideoVertical8KList = append(vars.VideoVertical8KList, currentVideoPath)
} else if height < 10000 {
vars.VideoVertical9KList = append(vars.VideoVertical9KList, currentVideoPath)
} else if height > 10000 {
} else if height >= 10000 {
vars.VideoVerticalHKList = append(vars.VideoVerticalHKList, currentVideoPath)
}
}
@@ -488,7 +509,7 @@ func handleSquareVideo(currentVideoPath string, width int, height int, suffix st
vars.VideoSquare8KList = append(vars.VideoSquare8KList, currentVideoPath)
} else if width < 10000 {
vars.VideoSquare9KList = append(vars.VideoSquare9KList, currentVideoPath)
} else if width > 10000 {
} else if width >= 10000 {
vars.VideoSquareHKList = append(vars.VideoSquareHKList, currentVideoPath)
}
}