Prechádzať zdrojové kódy

优化附件下载、新增公共方法

maxiaoshan 3 rokov pred
rodič
commit
157e2dbb94
2 zmenil súbory, kde vykonal 39 pridanie a 3 odobranie
  1. 11 3
      src/res/util/comm.lua
  2. 28 0
      src/spider/script.go

+ 11 - 3
src/res/util/comm.lua

@@ -517,6 +517,7 @@ function common.getFilesLinkByTag(href,tags,content,withend)
 	--dhtml=dhtml.."<a href='/123.doc'>123.doc</a>"
 	local alist = findListHtml(tags.." a", content)
 	local flist={}
+	local ahref={}--对href进行判重处理
 	for k,v in pairs(alist) do
 		local item={}
 		item["href"]="a:eq("..tostring(k-1).."):attr(href)"
@@ -550,8 +551,16 @@ function common.getFilesLinkByTag(href,tags,content,withend)
 		end
 	
 		if statehref~=nil and item["title"]~="" then
-			
-			table.insert(flist,item)
+			local has = false
+			for _,tmphref in pairs(ahref) do
+				if tmphref == item["href"] then
+					has = true
+				end
+			end
+			if not has then
+				table.insert(ahref,item["href"])
+				table.insert(flist,item)
+			end
 		end
 	end
 	return flist
@@ -568,7 +577,6 @@ function common.getFileAttachmentsArrayWithTag(href,tags,content,withend,param,h
 	--local nameTypeArr={"jpg","JPG","bid","pdf","PDF","doc","docx","xls","xlsx","zip","rar","swf","DOCX","DOC","PDF","XLS","XLSX","ZIP","RAR","SWF"}
 	local titleAndHrefList = common.getFilesLinkByTag(href,tags,content,withend)
 	for i,v in ipairs(titleAndHrefList) do
-		
 		local end_type = string.find(v["title"],v["ftype"].."$")
 		local file_name = ""
 		if end_type==nil or end_type=="" then

+ 28 - 0
src/spider/script.go

@@ -688,6 +688,34 @@ func (s *Script) LoadScript(code, script_file string, newstate bool) string {
 		S.Push(lua.LString(publishtime))
 		return 1
 	}))
+	//匹配
+	s.L.SetGlobal("stringFind", s.L.NewFunction(func(S *lua.LState) int {
+		regstr := S.ToString(-1)
+		text := S.ToString(-2)
+		reg := regexp.MustCompile(regstr)
+		result := reg.FindString(text)
+		isMatch := false
+		if result != "" {
+			isMatch = true
+		}
+		S.Push(lua.LString(result))
+		S.Push(lua.LBool(isMatch))
+		return 2
+	}))
+	//去除特殊标签中间内容
+	s.L.SetGlobal("getPureContent", s.L.NewFunction(func(S *lua.LState) int {
+		con := S.ToString(-1)
+		reg := regexp.MustCompile("(?s)<!%-%-.*?%-%->")
+		con = reg.ReplaceAllString(con, "")
+		// indexArr := reg.FindAllStringIndex(con, -1)
+		// for i := len(indexArr) - 1; i >= 0; i-- {
+		// 	if index := indexArr[i]; len(index) == 2 {
+		// 		con = con[:index[0]] + con[index[1]:]
+		// 	}
+		// }
+		S.Push(lua.LString(con))
+		return 1
+	}))
 	return ""
 }
 func dealHref(pageListUrl, href string) string {