fix: unable to sync files and save data issues

This commit is contained in:
Marvin Zhang
2024-06-25 14:58:54 +08:00
parent 460c8d958a
commit 5daeccb87d
12 changed files with 113 additions and 31 deletions

View File

@@ -80,10 +80,11 @@ func GetProjectList(c *gin.Context) {
}
// assign
var data []models.ProjectV2
for _, p := range projects {
p.Spiders = cache[p.Id]
projects = append(projects, p)
data = append(data, p)
}
HandleSuccessWithListData(c, projects, total)
HandleSuccessWithListData(c, data, total)
}

View File

@@ -363,6 +363,18 @@ func InitRoutes(app *gin.Engine) (err error) {
HandlerFunc: PostLogout,
},
})
RegisterActions(groups.AnonymousGroup, "/sync", []Action{
{
Method: http.MethodGet,
Path: "/:id/scan",
HandlerFunc: GetSyncScan,
},
{
Method: http.MethodGet,
Path: "/:id/download",
HandlerFunc: GetSyncDownload,
},
})
return nil
}

View File

@@ -0,0 +1,31 @@
package controllers
import (
"github.com/crawlab-team/crawlab/core/utils"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
"net/http"
"path/filepath"
)
func GetSyncScan(c *gin.Context) {
id := c.Param("id")
path := c.Query("path")
workspacePath := viper.GetString("workspace")
dirPath := filepath.Join(workspacePath, id, path)
files, err := utils.ScanDirectory(dirPath)
if err != nil {
HandleErrorInternalServerError(c, err)
return
}
c.AbortWithStatusJSON(http.StatusOK, files)
}
func GetSyncDownload(c *gin.Context) {
id := c.Param("id")
path := c.Query("path")
workspacePath := viper.GetString("workspace")
filePath := filepath.Join(workspacePath, id, path)
c.File(filePath)
}