From a2d13fae36a7350a9b57b290c9f769ce6ea42c5e Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Wed, 23 Jul 2025 14:55:04 +0800 Subject: [PATCH] feat: temporarily disable batch file saving route and implement alternative handler in spider controller --- core/controllers/router.go | 16 ++++++++------- core/controllers/spider.go | 22 +++++++++++++++++++++ core/task/handler/service.go | 2 +- docker/base-image/install/deps/deps.sh | 5 ++++- frontend/crawlab-ui/src/store/utils/file.ts | 4 ++-- 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/core/controllers/router.go b/core/controllers/router.go index 373f0dd7..3a61d35d 100644 --- a/core/controllers/router.go +++ b/core/controllers/router.go @@ -318,13 +318,14 @@ func InitRoutes(app *gin.Engine) (err error) { Description: "Save a spider file", HandlerFunc: PostSpiderSaveFile, }, - { - Method: http.MethodPost, - Path: "/:id/files/save/batch", - Name: "Save Spider Files", - Description: "Save multiple spider files", - HandlerFunc: PostSpiderSaveFiles, - }, + // TODO: temporarily disabled due to compatibility issue + //{ + // Method: http.MethodPost, + // Path: "/:id/files/save/batch", + // Name: "Save Spider Files", + // Description: "Save multiple spider files", + // HandlerFunc: PostSpiderSaveFiles, + //}, { Method: http.MethodPost, Path: "/:id/files/save/dir", @@ -375,6 +376,7 @@ func InitRoutes(app *gin.Engine) (err error) { HandlerFunc: GetSpiderResults, }, }...)) + groups.AuthGroup.GinRouterGroup().POST("/spiders/:id/files/save/batch", PostSpiderSaveFilesGin) // TODO: temporarily use this due to compatibility issue RegisterController(groups.AuthGroup.Group("", "Schedules", "APIs for schedules management"), "/schedules", NewController[models.Schedule]([]Action{ { Method: http.MethodGet, diff --git a/core/controllers/spider.go b/core/controllers/spider.go index ea615161..a4ef5931 100644 --- a/core/controllers/spider.go +++ b/core/controllers/spider.go @@ -3,6 +3,7 @@ package controllers import ( "github.com/crawlab-team/crawlab/core/entity" "mime/multipart" + "net/http" "os" "path/filepath" "sync" @@ -429,6 +430,27 @@ func PostSpiderSaveFiles(c *gin.Context, params *PostSpiderSaveFilesParams) (res return PostBaseFileSaveMany(filepath.Join(rootPath, params.TargetDirectory), form) } +// PostSpiderSaveFilesGin handles saving multiple files to a spider's directory via Gin context TODO: temporary solution +func PostSpiderSaveFilesGin(c *gin.Context) { + targetDirectory := c.PostForm("targetDirectory") + rootPath, err := getSpiderRootPathByContext(c) + if err != nil { + c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } + form, err := c.MultipartForm() + if err != nil { + c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } + _, err = PostBaseFileSaveMany(filepath.Join(rootPath, targetDirectory), form) + if err != nil { + c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + HandleSuccessWithData(c, nil) +} + type PostSpiderSaveDirParams struct { Id string `path:"id" description:"Spider ID" format:"objectid" pattern:"^[0-9a-fA-F]{24}$"` Path string `json:"path" description:"File path to save"` diff --git a/core/task/handler/service.go b/core/task/handler/service.go index bcd1b37d..26b8aefa 100644 --- a/core/task/handler/service.go +++ b/core/task/handler/service.go @@ -174,7 +174,7 @@ func (svc *Service) fetchAndRunTasks() { case <-svc.fetchTicker.C: // Use a separate context with timeout for each operation if err := svc.processFetchCycle(); err != nil { - svc.Debugf("fetch cycle error: %v", err) + //svc.Debugf("fetch cycle error: %v", err) } } } diff --git a/docker/base-image/install/deps/deps.sh b/docker/base-image/install/deps/deps.sh index 1143781d..c6f7ed01 100644 --- a/docker/base-image/install/deps/deps.sh +++ b/docker/base-image/install/deps/deps.sh @@ -19,7 +19,10 @@ apt-get install -y \ iputils-ping \ nginx \ jq \ - net-tools + net-tools \ + fonts-wqy-zenhei \ + fonts-noto-cjk \ + fontconfig # Add source /etc/profile to ~/.bashrc echo "source /etc/profile" >> ~/.bashrc \ No newline at end of file diff --git a/frontend/crawlab-ui/src/store/utils/file.ts b/frontend/crawlab-ui/src/store/utils/file.ts index a06603fc..af114d08 100644 --- a/frontend/crawlab-ui/src/store/utils/file.ts +++ b/frontend/crawlab-ui/src/store/utils/file.ts @@ -74,8 +74,8 @@ export const getBaseFileStoreActions = ( { commit }: StoreActionContext, { id, path }: FileRequestPayload ) => { - const res = await get(`${endpoint}/${id}/files/list`, { path }); - const navItems = res.data as FileNavItem[]; + const res = await get>(`${endpoint}/${id}/files/list`, { path }); + const navItems = res.data || []; commit('setFileNavItems', navItems); return res; },