feat: rebind mobile

This commit is contained in:
zzw
2026-10-21 13:29:03 +08:00
parent 113756fd46
commit 6107ac8d9d
47 changed files with 2210 additions and 289 deletions
@@ -0,0 +1,88 @@
package callback
import (
"archive/zip"
"io"
"os"
"path/filepath"
"strings"
"lone-services/pkg/utils"
"lone-services/services/analysis/internal/dao"
)
func HandleTaskZip(zipPath string) (*dao.HandleZipResource, string, error) {
targetDir := filepath.Dir(zipPath)
subDirName := strings.TrimSuffix(filepath.Base(zipPath), filepath.Ext(zipPath))
finalDir := filepath.Join(targetDir, subDirName)
coverPath, err := unzipImages(zipPath, finalDir)
if err != nil {
return nil, utils.StringEmpty, err
}
return &dao.HandleZipResource{
FilePath: zipPath,
FinalDir: finalDir,
TargetDir: targetDir,
}, coverPath, nil
}
func unzipImages(zipPath, targetDir string) (string, error) {
if err := os.MkdirAll(targetDir, os.ModePerm); err != nil {
return utils.StringEmpty, err
}
r, err := zip.OpenReader(zipPath)
if err != nil {
return utils.StringEmpty, err
}
defer r.Close()
var crossMidPath string
for _, f := range r.File {
ext := strings.ToLower(filepath.Ext(f.Name))
if !isImageExt(ext) {
continue
}
rc, err := f.Open()
if err != nil {
continue
}
filename := filepath.Base(f.Name)
if filename == utils.StringEmpty {
_ = rc.Close()
continue
}
fullPath := filepath.Join(targetDir, filename)
dst, err := os.Create(fullPath)
if err != nil {
_ = rc.Close()
continue
}
_, copyErr := io.Copy(dst, rc)
_ = dst.Close()
_ = rc.Close()
if copyErr != nil {
continue
}
if strings.EqualFold(filename, "cross_mid.jpg") {
crossMidPath = fullPath
}
}
return crossMidPath, nil
}
func isImageExt(ext string) bool {
switch ext {
case ".jpg", ".jpeg", ".png", ".gif":
return true
default:
return false
}
}