From 33fbf96efb6da880d56aa7e148c57a2943f778ee Mon Sep 17 00:00:00 2001 From: marvzhang Date: Fri, 3 Jan 2020 11:12:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/main.go | 1 + backend/routes/system.go | 4 ++ backend/services/system.go | 96 +++++++++++++++++++++----------------- 3 files changed, 57 insertions(+), 44 deletions(-) diff --git a/backend/main.go b/backend/main.go index c7ae7ec1..7dd5046e 100644 --- a/backend/main.go +++ b/backend/main.go @@ -149,6 +149,7 @@ func main() { authGroup.GET("/nodes/:id/deps/installed", routes.GetInstalledDepList) // 节点已安装第三方依赖列表 authGroup.POST("/nodes/:id/deps/install", routes.InstallDep) // 节点安装依赖 authGroup.POST("/nodes/:id/deps/uninstall", routes.UninstallDep) // 节点卸载依赖 + authGroup.POST("/nodes/:id/langs/install", routes.InstallLang) // 节点安装语言 // 爬虫 authGroup.GET("/spiders", routes.GetSpiderList) // 爬虫列表 authGroup.GET("/spiders/:id", routes.GetSpider) // 爬虫详情 diff --git a/backend/routes/system.go b/backend/routes/system.go index 43b37cf9..0a388d0f 100644 --- a/backend/routes/system.go +++ b/backend/routes/system.go @@ -221,3 +221,7 @@ func GetDepJson(c *gin.Context) { Data: dep, }) } + +func InstallLang(c *gin.Context) { + //lang := c.Query("lang") +} diff --git a/backend/services/system.go b/backend/services/system.go index f1a4c4e6..759f52e0 100644 --- a/backend/services/system.go +++ b/backend/services/system.go @@ -20,27 +20,6 @@ import ( "sync" ) -type PythonDepJsonData struct { - Info PythonDepJsonDataInfo `json:"info"` -} - -type PythonDepJsonDataInfo struct { - Name string `json:"name"` - Summary string `json:"summary"` - Version string `json:"version"` -} - -type PythonDepNameDict struct { - Name string `json:"name"` - Weight int `json:"weight"` -} - -type PythonDepNameDictSlice []PythonDepNameDict - -func (s PythonDepNameDictSlice) Len() int { return len(s) } -func (s PythonDepNameDictSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } -func (s PythonDepNameDictSlice) Less(i, j int) bool { return s[i].Weight > s[j].Weight } - // 系统信息 chan 映射 var SystemInfoChanMap = utils.NewChanMap() @@ -120,6 +99,55 @@ func IsInstalledLang(nodeId string, lang entity.Lang) bool { return false } +// 是否已安装该依赖 +func IsInstalledDep(installedDepList []entity.Dependency, dep entity.Dependency) bool { + for _, _dep := range installedDepList { + if strings.ToLower(_dep.Name) == strings.ToLower(dep.Name) { + return true + } + } + return false +} + +// 初始化函数 +func InitDepsFetcher() error { + c := cron.New(cron.WithSeconds()) + c.Start() + if _, err := c.AddFunc("0 */5 * * * *", UpdatePythonDepList); err != nil { + return err + } + + go func() { + UpdatePythonDepList() + }() + return nil +} + +// ========= +// Python +// ========= + +type PythonDepJsonData struct { + Info PythonDepJsonDataInfo `json:"info"` +} + +type PythonDepJsonDataInfo struct { + Name string `json:"name"` + Summary string `json:"summary"` + Version string `json:"version"` +} + +type PythonDepNameDict struct { + Name string `json:"name"` + Weight int `json:"weight"` +} + +type PythonDepNameDictSlice []PythonDepNameDict + +func (s PythonDepNameDictSlice) Len() int { return len(s) } +func (s PythonDepNameDictSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +func (s PythonDepNameDictSlice) Less(i, j int) bool { return s[i].Weight > s[j].Weight } + // 获取Python本地依赖列表 func GetPythonDepList(nodeId string, searchDepName string) ([]entity.Dependency, error) { var list []entity.Dependency @@ -357,16 +385,6 @@ func GetPythonRemoteInstalledDepList(nodeId string) ([]entity.Dependency, error) return depList, nil } -// 是否已安装该依赖 -func IsInstalledDep(installedDepList []entity.Dependency, dep entity.Dependency) bool { - for _, _dep := range installedDepList { - if strings.ToLower(_dep.Name) == strings.ToLower(dep.Name) { - return true - } - } - return false -} - // 安装Python本地依赖 func InstallPythonLocalDep(depName string) (string, error) { // 依赖镜像URL @@ -412,16 +430,6 @@ func UninstallPythonRemoteDep(nodeId string, depName string) (string, error) { return output, nil } -// 初始化函数 -func InitDepsFetcher() error { - c := cron.New(cron.WithSeconds()) - c.Start() - if _, err := c.AddFunc("0 */5 * * * *", UpdatePythonDepList); err != nil { - return err - } - - go func() { - UpdatePythonDepList() - }() - return nil -} +// ============== +// Node.js +// ==============