Răsfoiți Sursa

sendListNum方法

maxiaoshan 3 ani în urmă
părinte
comite
02c577d64d
3 a modificat fișierele cu 23 adăugiri și 4 ștergeri
  1. 12 4
      src/front/spider.go
  2. 7 0
      src/spider/script.go
  3. 4 0
      src/util/util.go

+ 12 - 4
src/front/spider.go

@@ -374,7 +374,7 @@ func (f *Front) SaveStep() {
 			param["iscopycontent"] = f.StepRe3.Checked
 			//
 			param["listisfilter"] = ListFilterReg.MatchString(f.Step2.Expert) //列表页校验是否含“--关键词过滤”
-			matchLua := LuaTextCheck(f.Step2.Expert, f.Step3.Expert)
+			matchLua, msg := LuaTextCheck(f.Step2.Expert, f.Step3.Expert, f.Step2.Types)
 			if !matchLua {
 				issave := spider.SaveSpider(code, param) //保存脚本
 				if issave {
@@ -389,7 +389,7 @@ func (f *Front) SaveStep() {
 					rep["msg"] = "保存失败"
 				}
 			} else {
-				rep["msg"] = "保存失败,代码中含有禁用方法"
+				rep["msg"] = "保存失败," + msg
 			}
 			rep["code"] = util.Se.Encode2Hex(code)
 			f.ServeJson(rep)
@@ -398,9 +398,17 @@ func (f *Front) SaveStep() {
 }
 
 //检查列表页和三级页代码中是否含lua原生方法
-func LuaTextCheck(list, detail string) bool {
+func LuaTextCheck(list, detail string, type_list int) (b bool, msg string) {
 	defer qu.Catch()
-	return LuaReg.MatchString(list) || LuaReg.MatchString(detail)
+	if LuaReg.MatchString(list) || LuaReg.MatchString(detail) {
+		b = true
+		msg = "代码中含有lua原生方法;"
+	}
+	if type_list != 0 && !strings.Contains(list, "sendListNum") { //列表页专家模式且不含sendListNum
+		b = true
+		msg = "代码中缺少sendListNum方法;" + msg
+	}
+	return
 }
 
 func (f *Front) Assort() {

+ 7 - 0
src/spider/script.go

@@ -152,6 +152,13 @@ func (s *Script) LoadScript(downloadnode, script string, isfile ...string) {
 		S.Push(ret)
 		return 1
 	}))
+	//推送列表页下载数据量
+	s.L.SetGlobal("sendListNum", s.L.NewFunction(func(S *lua.LState) int {
+		table := S.ToTable(-1)
+		list := util.TableToMap(table)
+		qu.Debug(len(list))
+		return 1
+	}))
 	s.L.SetGlobal("findMap", s.L.NewFunction(func(S *lua.LState) int {
 		qmap := S.ToTable(-2)
 		content := S.ToString(-1)

+ 4 - 0
src/util/util.go

@@ -151,6 +151,10 @@ func SpiderPassCheckLua(liststr, contentstr string, lua map[string]interface{})
 			msg = append(msg, "检查代码title的完整性")
 		}
 	}
+	//4.检测sendListNum
+	if !strings.Contains(liststr, "sendListNum") {
+		msg = append(msg, "sendListNum方法缺失")
+	}
 	return strings.Join(msg, ",")
 }