mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-23 17:31:11 +01:00
111 lines
2.2 KiB
Go
111 lines
2.2 KiB
Go
package routes
|
|
|
|
import (
|
|
"crawlab/constants"
|
|
"crawlab/entity"
|
|
"crawlab/services"
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func GetLangList(c *gin.Context) {
|
|
nodeId := c.Param("id")
|
|
c.JSON(http.StatusOK, Response{
|
|
Status: "ok",
|
|
Message: "success",
|
|
Data: services.GetLangList(nodeId),
|
|
})
|
|
}
|
|
|
|
func GetDepList(c *gin.Context) {
|
|
nodeId := c.Param("id")
|
|
lang := c.Query("lang")
|
|
depName := c.Query("dep_name")
|
|
|
|
var depList []entity.Dependency
|
|
if lang == constants.Python {
|
|
list, err := services.GetPythonDepList(nodeId, depName)
|
|
if err != nil {
|
|
HandleError(http.StatusInternalServerError, c, err)
|
|
return
|
|
}
|
|
depList = list
|
|
} else {
|
|
HandleErrorF(http.StatusBadRequest, c, fmt.Sprintf("%s is not implemented", lang))
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, Response{
|
|
Status: "ok",
|
|
Message: "success",
|
|
Data: depList,
|
|
})
|
|
}
|
|
|
|
func GetInstalledDepList(c *gin.Context) {
|
|
nodeId := c.Param("id")
|
|
lang := c.Query("lang")
|
|
var depList []entity.Dependency
|
|
if lang == constants.Python {
|
|
list, err := services.GetPythonInstalledDepList(nodeId)
|
|
if err != nil {
|
|
HandleError(http.StatusInternalServerError, c, err)
|
|
return
|
|
}
|
|
depList = list
|
|
} else {
|
|
HandleErrorF(http.StatusBadRequest, c, fmt.Sprintf("%s is not implemented", lang))
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, Response{
|
|
Status: "ok",
|
|
Message: "success",
|
|
Data: depList,
|
|
})
|
|
}
|
|
|
|
func GetAllDepList(c *gin.Context) {
|
|
lang := c.Query("lang")
|
|
depName := c.Query("dep_name")
|
|
|
|
// 获取所有依赖列表
|
|
var list []string
|
|
if lang == constants.Python {
|
|
_list, err := services.GetPythonDepListFromRedis()
|
|
if err != nil {
|
|
HandleError(http.StatusInternalServerError, c, err)
|
|
return
|
|
}
|
|
list = _list
|
|
} else {
|
|
HandleErrorF(http.StatusBadRequest, c, fmt.Sprintf("%s is not implemented", lang))
|
|
return
|
|
}
|
|
|
|
// 过滤依赖列表
|
|
var depList []string
|
|
for _, name := range list {
|
|
if strings.HasPrefix(strings.ToLower(name), strings.ToLower(depName)) {
|
|
depList = append(depList, name)
|
|
}
|
|
}
|
|
|
|
// 只取前20
|
|
var returnList []string
|
|
for i, name := range depList {
|
|
if i >= 10 {
|
|
break
|
|
}
|
|
returnList = append(returnList, name)
|
|
}
|
|
|
|
c.JSON(http.StatusOK, Response{
|
|
Status: "ok",
|
|
Message: "success",
|
|
Data: returnList,
|
|
})
|
|
}
|