mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
fix: unable to sync files and save data issues
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
31
core/controllers/sync_v2.go
Normal file
31
core/controllers/sync_v2.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user