f2fd4acbfd
CI / changes (push) Successful in 1m45s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 1s
CI / analysis (push) Successful in 47s
CI / bff (push) Successful in 30s
CI / chore (push) Successful in 0s
CI / equipment (push) Successful in 1s
CI / express (push) Successful in 0s
CI / factory (push) Successful in 1s
CI / message (push) Successful in 47s
CI / order (push) Successful in 0s
CI / payment (push) Successful in 1s
CI / percutaneous (push) Successful in 0s
CI / product (push) Successful in 1s
CI / record (push) Successful in 0s
CI / sale (push) Successful in 0s
CI / store (push) Successful in 0s
CI / support (push) Successful in 0s
CI / task (push) Successful in 0s
CI / user (push) Successful in 0s
CI / water (push) Successful in 0s
CI / wecom (push) Successful in 0s
CI / ws (push) Successful in 0s
82 lines
2.2 KiB
Go
82 lines
2.2 KiB
Go
package callback
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"time"
|
|
|
|
"lone-services/pkg/utils"
|
|
"lone-services/services/analysis/internal/dao"
|
|
analysisoss "lone-services/services/analysis/internal/oss"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
func ProcessUpload(ctx context.Context, payload analysisoss.CallbackPayload) error {
|
|
if payload.TaskId == utils.StringEmpty || payload.Object == utils.StringEmpty {
|
|
return fmt.Errorf("callback missing task_id or object")
|
|
}
|
|
|
|
sess, err := analysisoss.LoadUploadSession(ctx, payload.TaskId)
|
|
if err != nil {
|
|
return fmt.Errorf("load upload session: %w", err)
|
|
}
|
|
if sess.DateDir == utils.StringEmpty {
|
|
return fmt.Errorf("upload session date_dir empty")
|
|
}
|
|
|
|
downloadURL, err := BuildDownloadURL(payload.Object)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
subTaskId := uuid.New().String()
|
|
subDirName := strconv.FormatInt(time.Now().UnixMilli(), 10)
|
|
targetDir := filepath.Join(utils.GetConfigString("file.analysis_path"), sess.DateDir, payload.TaskId)
|
|
if err = os.MkdirAll(targetDir, os.ModePerm); err != nil {
|
|
return fmt.Errorf("mkdir analysis path: %w", err)
|
|
}
|
|
zipPath := filepath.Join(targetDir, subDirName+".zip")
|
|
|
|
if err = DownloadFile(downloadURL, zipPath); err != nil {
|
|
return fmt.Errorf("download zip: %w", err)
|
|
}
|
|
|
|
pathRes, coverPath, err := HandleTaskZip(zipPath)
|
|
if err != nil {
|
|
return fmt.Errorf("handle zip: %w", err)
|
|
}
|
|
|
|
if err = CacheUploadedLights(payload.TaskId, pathRes.FinalDir); err != nil {
|
|
logx.WithContext(ctx).Errorf("cache uploaded lights failed: %v", err)
|
|
}
|
|
|
|
if utils.GetConfigInt("switch.facepp") == utils.NumberOne {
|
|
logx.WithContext(ctx).Infof("facepp skip task_id=%s", payload.TaskId)
|
|
}
|
|
|
|
if utils.GetConfigInt("switch.analysis") == utils.NumberOne {
|
|
if err = NotifyPythonService(payload.TaskId, subTaskId, pathRes.FinalDir); err != nil {
|
|
logx.WithContext(ctx).Errorf("notify python failed: %v", err)
|
|
}
|
|
}
|
|
|
|
ts := dao.TaskTimeStamp{
|
|
TaskId: payload.TaskId,
|
|
SubTaskId: subTaskId,
|
|
ProcessStartTs: time.Now().UnixMilli(),
|
|
}
|
|
userId := sess.SkinUserId()
|
|
if userId < utils.NumberOne {
|
|
userId = sess.UserId
|
|
}
|
|
if err = SaveTask(ts, userId, pathRes, coverPath); err != nil {
|
|
return err
|
|
}
|
|
return SaveSubTask(ts, pathRes)
|
|
}
|