diff --git a/relay/common/relay_info.go b/relay/common/relay_info.go index e4421fc1..7d4f063c 100644 --- a/relay/common/relay_info.go +++ b/relay/common/relay_info.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "strconv" "strings" "time" @@ -690,6 +691,7 @@ func (t *TaskSubmitReq) UnmarshalJSON(data []byte) error { type Alias TaskSubmitReq aux := &struct { Metadata json.RawMessage `json:"metadata,omitempty"` + Duration json.RawMessage `json:"duration,omitempty"` *Alias }{ Alias: (*Alias)(t), @@ -699,6 +701,20 @@ func (t *TaskSubmitReq) UnmarshalJSON(data []byte) error { return err } + if len(aux.Duration) > 0 { + var durationInt int + if err := common.Unmarshal(aux.Duration, &durationInt); err == nil { + t.Duration = durationInt + } else { + var durationStr string + if err := common.Unmarshal(aux.Duration, &durationStr); err == nil && durationStr != "" { + if v, err := strconv.Atoi(durationStr); err == nil { + t.Duration = v + } + } + } + } + if len(aux.Metadata) > 0 { var metadataStr string if err := common.Unmarshal(aux.Metadata, &metadataStr); err == nil && metadataStr != "" { diff --git a/relay/common/relay_utils.go b/relay/common/relay_utils.go index 3cbb18c2..18df77a6 100644 --- a/relay/common/relay_utils.go +++ b/relay/common/relay_utils.go @@ -204,7 +204,9 @@ func ValidateBasicTaskRequest(c *gin.Context, info *RelayInfo, action string) *d if err != nil { return createTaskError(err, "invalid_multipart_form", http.StatusBadRequest, true) } - } else if err := common.UnmarshalBodyReusable(c, &req); err != nil { + } + // 为了metadata字段的兼容性,统一UnmarshalBodyReusable + if err := common.UnmarshalBodyReusable(c, &req); err != nil { return createTaskError(err, "invalid_request", http.StatusBadRequest, true) }