mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-26 17:49:15 +01:00
refactor: enhance parameter handling and improve code clarity
- Updated GetListParams to set a default sort option for better query handling. - Enhanced PostSpiderRunParams to include a default mode and improved error handling for missing spider. - Added parameters field to ChatMessageContent for more flexible message content management. - Refactored getNodeIds method to simplify mode handling and removed unnecessary error checks. - Improved ChatMessageAction component to display parameters and response sections more effectively, enhancing user experience.
This commit is contained in:
@@ -63,7 +63,7 @@ type BaseController[T any] struct {
|
||||
|
||||
type GetListParams struct {
|
||||
Filter string `query:"filter" description:"Filter query"`
|
||||
Sort string `query:"sort" description:"Sort options"`
|
||||
Sort string `query:"sort" default:"-_id" description:"Sort options"`
|
||||
Page int `query:"page" default:"1" description:"Page number" minimum:"1"`
|
||||
Size int `query:"size" default:"10" description:"Page size" minimum:"1"`
|
||||
All bool `query:"all" default:"false" description:"Whether to get all items"`
|
||||
|
||||
@@ -674,7 +674,7 @@ func PostSpiderExport(c *gin.Context, _ *PostSpiderExportParams) (err error) {
|
||||
|
||||
type PostSpiderRunParams struct {
|
||||
Id string `path:"id" description:"Spider ID" format:"objectid" pattern:"^[0-9a-fA-F]{24}$"`
|
||||
Mode string `json:"mode" description:"Run mode" enum:"random,all,selected-nodes"`
|
||||
Mode string `json:"mode" description:"Run mode: random,all,selected-nodes" default:"random" enum:"random,all,selected-nodes"`
|
||||
NodeIds []string `json:"node_ids" description:"Node IDs, used in selected-nodes mode"`
|
||||
Cmd string `json:"cmd" description:"Command"`
|
||||
Param string `json:"param" description:"Parameters"`
|
||||
@@ -688,6 +688,12 @@ func PostSpiderRun(c *gin.Context, params *PostSpiderRunParams) (response *Respo
|
||||
return GetErrorResponse[[]primitive.ObjectID](errors.BadRequestf("invalid id format"))
|
||||
}
|
||||
|
||||
// get spider
|
||||
s, err := service.NewModelService[models.Spider]().GetById(id)
|
||||
if err != nil {
|
||||
return GetErrorResponse[[]primitive.ObjectID](errors.NotFoundf("spider not found"))
|
||||
}
|
||||
|
||||
// options
|
||||
var nodeIds []primitive.ObjectID
|
||||
if len(params.NodeIds) > 0 {
|
||||
@@ -714,6 +720,18 @@ func PostSpiderRun(c *gin.Context, params *PostSpiderRunParams) (response *Respo
|
||||
ScheduleId: scheduleId,
|
||||
Priority: params.Priority,
|
||||
}
|
||||
if opts.Mode == "" {
|
||||
opts.Mode = s.Mode
|
||||
}
|
||||
if opts.Cmd == "" {
|
||||
opts.Cmd = s.Cmd
|
||||
}
|
||||
if opts.Param == "" {
|
||||
opts.Param = s.Param
|
||||
}
|
||||
if opts.Priority == 0 {
|
||||
opts.Priority = s.Priority
|
||||
}
|
||||
|
||||
// user
|
||||
if u := GetUserFromContext(c); u != nil {
|
||||
|
||||
Reference in New Issue
Block a user