feat: enhance multipart validation with additional fields for model, seconds, and size
This commit is contained in:
parent
32f748cd7b
commit
d540020c3d
@ -109,6 +109,9 @@ func validateMultipartTaskRequest(c *gin.Context, info *RelayInfo, action string
|
|||||||
func ValidateMultipartDirect(c *gin.Context, info *RelayInfo) *dto.TaskError {
|
func ValidateMultipartDirect(c *gin.Context, info *RelayInfo) *dto.TaskError {
|
||||||
contentType := c.GetHeader("Content-Type")
|
contentType := c.GetHeader("Content-Type")
|
||||||
var prompt string
|
var prompt string
|
||||||
|
var model string
|
||||||
|
var seconds int
|
||||||
|
var size string
|
||||||
var hasInputReference bool
|
var hasInputReference bool
|
||||||
|
|
||||||
if strings.HasPrefix(contentType, "multipart/form-data") {
|
if strings.HasPrefix(contentType, "multipart/form-data") {
|
||||||
@ -127,10 +130,22 @@ func ValidateMultipartDirect(c *gin.Context, info *RelayInfo) *dto.TaskError {
|
|||||||
if _, ok := form.Value["model"]; !ok {
|
if _, ok := form.Value["model"]; !ok {
|
||||||
return createTaskError(fmt.Errorf("model field is required"), "missing_model", http.StatusBadRequest, true)
|
return createTaskError(fmt.Errorf("model field is required"), "missing_model", http.StatusBadRequest, true)
|
||||||
}
|
}
|
||||||
|
model = form.Value["model"][0]
|
||||||
|
|
||||||
if _, ok := form.File["input_reference"]; ok {
|
if _, ok := form.File["input_reference"]; ok {
|
||||||
hasInputReference = true
|
hasInputReference = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ss, ok := form.Value["seconds"]; ok {
|
||||||
|
sInt := common.String2Int(ss[0])
|
||||||
|
if sInt > seconds {
|
||||||
|
seconds = common.String2Int(ss[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if sz, ok := form.Value["size"]; ok {
|
||||||
|
size = sz[0]
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
var req TaskSubmitReq
|
var req TaskSubmitReq
|
||||||
if err := common.UnmarshalBodyReusable(c, &req); err != nil {
|
if err := common.UnmarshalBodyReusable(c, &req); err != nil {
|
||||||
@ -138,6 +153,8 @@ func ValidateMultipartDirect(c *gin.Context, info *RelayInfo) *dto.TaskError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
prompt = req.Prompt
|
prompt = req.Prompt
|
||||||
|
model = req.Model
|
||||||
|
seconds = req.Duration
|
||||||
|
|
||||||
if strings.TrimSpace(req.Model) == "" {
|
if strings.TrimSpace(req.Model) == "" {
|
||||||
return createTaskError(fmt.Errorf("model field is required"), "missing_model", http.StatusBadRequest, true)
|
return createTaskError(fmt.Errorf("model field is required"), "missing_model", http.StatusBadRequest, true)
|
||||||
@ -157,18 +174,14 @@ func ValidateMultipartDirect(c *gin.Context, info *RelayInfo) *dto.TaskError {
|
|||||||
action = constant.TaskActionGenerate
|
action = constant.TaskActionGenerate
|
||||||
}
|
}
|
||||||
info.Action = action
|
info.Action = action
|
||||||
model := form.Value["model"][0]
|
|
||||||
if strings.HasPrefix(model, "sora-2") {
|
if strings.HasPrefix(model, "sora-2") {
|
||||||
seconds := 4
|
|
||||||
size := "720x1280"
|
if size == "" {
|
||||||
if ss, ok := form.Value["seconds"]; ok {
|
size = "720x1280"
|
||||||
sInt := common.String2Int(ss[0])
|
|
||||||
if sInt > seconds {
|
|
||||||
seconds = common.String2Int(ss[0])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if s, ok := form.Value["size"]; ok {
|
|
||||||
size = s[0]
|
if seconds <= 0 {
|
||||||
|
seconds = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
if model == "sora-2" && !lo.Contains([]string{"720x1280", "1280x720"}, size) {
|
if model == "sora-2" && !lo.Contains([]string{"720x1280", "1280x720"}, size) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user