feat: temporarily disable batch file saving route and implement alternative handler in spider controller

This commit is contained in:
Marvin Zhang
2025-07-23 14:55:04 +08:00
parent b4288b08a5
commit a2d13fae36
5 changed files with 38 additions and 11 deletions

View File

@@ -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,

View File

@@ -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"`

View File

@@ -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)
}
}
}

View File

@@ -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

View File

@@ -74,8 +74,8 @@ export const getBaseFileStoreActions = <S extends BaseFileStoreState>(
{ commit }: StoreActionContext<S>,
{ id, path }: FileRequestPayload
) => {
const res = await get(`${endpoint}/${id}/files/list`, { path });
const navItems = res.data as FileNavItem[];
const res = await get<any, ResponseWithData<FileNavItem[]>>(`${endpoint}/${id}/files/list`, { path });
const navItems = res.data || [];
commit('setFileNavItems', navItems);
return res;
},