maxiaoshan hace 2 años
padre
commit
6c6ce8e2e6
Se han modificado 2 ficheros con 41 adiciones y 22 borrados
  1. 4 0
      src/res/util/comm.lua
  2. 37 22
      src/spider/script.go

+ 4 - 0
src/res/util/comm.lua

@@ -587,6 +587,10 @@ function common.getFileAttachmentsArrayWithTag(href,tags,content,withend,param,h
 		local url,name,size,ftype,fid=downloadFile(file_name, v["href"], "get",param,head,ck)
 		-- 附件原地址(默认为空)
 		local init_url = v["href"]
+		local r,b = stringFind(init_url,"data:image")
+		if b then
+			init_url = ""
+		end
 		if url == "" then
 			local u = 0
 			while u < 2 do

+ 37 - 22
src/spider/script.go

@@ -293,30 +293,46 @@ func (s *Script) LoadScript(downloadnode, script string, isfile ...string) {
 		url := S.ToString(-5)
 		fileName := S.ToString(-6)
 		ishttps := strings.Contains(url, "https")
-		var mycookie []*http.Cookie
-		if cookie != "{}" {
-			json.Unmarshal([]byte(cookie), &mycookie)
-		} else {
-			mycookie = make([]*http.Cookie, 0)
-		}
-		fileName = strings.TrimSpace(fileName)
-		url = strings.TrimSpace(url)
-		ret := DownloadFile(s.Downloader, url, method, util.GetTable(param), util.GetTable(head), mycookie, s.Encoding, false, ishttps, "", s.Timeout)
+		base64UrlReg := regexp.MustCompile("data:image")
+		indexArr := base64UrlReg.FindStringIndex(url)
 		name, size, ftype, fid := "", "", "", ""
-		qu.Debug(GarbledCodeReg.FindAllString(string(ret), -1), len(ret))
-		if ret == nil || len(ret) < 1024*5 {
-			qu.Debug("下载文件出错!")
-		} else {
-			ftype = qu.GetFileType(ret)
-			if (ftype == "docx" || ftype == "doc") && len(GarbledCodeReg.FindAllString(string(ret), -1)) > 10 {
-				url, name, size, ftype, fid = "附件中含有乱码", "附件中含有乱码", "", "", ""
+		//base64 url
+		if len(indexArr) == 2 { //base64 http://www.mmjyjt.com/data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqAAAAOwCAYAAAD
+			//截取base64
+			start := indexArr[0]
+			url = url[start:]
+			fileName = "文件下载.jpg"
+			index := strings.Index(url, ",")
+			dec := base64.NewDecoder(base64.StdEncoding, strings.NewReader(url[index+1:]))
+			ret, err := io.ReadAll(dec)
+			if err == nil && len(ret) > 0 {
+				url, name, size, ftype, fid = util.UploadFile(s.SCode, fileName, "", ret)
+			}
+		} else { //正常url
+			var mycookie []*http.Cookie
+			if cookie != "{}" {
+				json.Unmarshal([]byte(cookie), &mycookie)
 			} else {
-				url, name, size, ftype, fid = util.UploadFile(s.SCode, fileName, url, ret)
+				mycookie = make([]*http.Cookie, 0)
 			}
-		}
-		if strings.TrimSpace(ftype) == "" {
-			if len(path.Ext(name)) > 0 {
-				ftype = path.Ext(name)[1:]
+			fileName = strings.TrimSpace(fileName)
+			url = strings.TrimSpace(url)
+			ret := DownloadFile(s.Downloader, url, method, util.GetTable(param), util.GetTable(head), mycookie, s.Encoding, false, ishttps, "", s.Timeout)
+			qu.Debug(GarbledCodeReg.FindAllString(string(ret), -1), len(ret))
+			if ret == nil || len(ret) < 1024*5 {
+				qu.Debug("下载文件出错!")
+			} else {
+				ftype = qu.GetFileType(ret)
+				if (ftype == "docx" || ftype == "doc") && len(GarbledCodeReg.FindAllString(string(ret), -1)) > 10 {
+					url, name, size, ftype, fid = "附件中含有乱码", "附件中含有乱码", "", "", ""
+				} else {
+					url, name, size, ftype, fid = util.UploadFile(s.SCode, fileName, url, ret)
+				}
+			}
+			if strings.TrimSpace(ftype) == "" {
+				if len(path.Ext(name)) > 0 {
+					ftype = path.Ext(name)[1:]
+				}
 			}
 		}
 		S.Push(lua.LString(url))
@@ -600,7 +616,6 @@ func (s *Script) LoadScript(downloadnode, script string, isfile ...string) {
 	s.L.SetGlobal("goRunJs", s.L.NewFunction(func(S *lua.LState) int {
 		param := S.ToString(-2) //list or detail
 		step := S.ToString(-1)  //参数
-		qu.Debug("111111111")
 		result := gojs.GoRunJsGetResult(s.SCode, param, step)
 		qu.Debug("Go Run Js Result:", param, step, result)
 		S.Push(lua.LString(result))