|
@@ -15,6 +15,7 @@ import (
|
|
|
"encoding/json"
|
|
|
"github.com/shopspring/decimal"
|
|
|
gojs "gorunjs/client"
|
|
|
+ "io"
|
|
|
"io/ioutil"
|
|
|
mu "mfw/util"
|
|
|
"net/http"
|
|
@@ -241,42 +242,62 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
|
|
|
url := S.ToString(-5)
|
|
|
fileName := S.ToString(-6)
|
|
|
ishttps := strings.Contains(url, "https")
|
|
|
- var mycookie []*http.Cookie
|
|
|
- if cookie != "{}" {
|
|
|
- json.Unmarshal([]byte(cookie), &mycookie)
|
|
|
+ //base64匹配
|
|
|
+ base64UrlReg := regexp.MustCompile("data:image")
|
|
|
+ indexArr := base64UrlReg.FindStringIndex(url)
|
|
|
+ name, size, ftype, fid := "", "", "", ""
|
|
|
+ var ret []byte
|
|
|
+ var err error
|
|
|
+ //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 {
|
|
|
- mycookie = make([]*http.Cookie, 0)
|
|
|
- }
|
|
|
- fileName = strings.TrimSpace(fileName)
|
|
|
- url = strings.TrimSpace(url)
|
|
|
- var retLen int64
|
|
|
- ret := DownloadFile(&retLen, s.Downloader, url, method, util.GetTable(param), util.GetTable(head), mycookie, s.Encoding, s.Userproxy, ishttps, s.SCode, s.Timeout)
|
|
|
- //流量统计
|
|
|
- //if retLen > 0 {
|
|
|
- // key := Today + "+" + code
|
|
|
- // if sf, ok := SpiderFlowMap.Load(key); ok && sf != nil {
|
|
|
- // if sfMap, ok := sf.(*SpiderFlow); ok {
|
|
|
- // sfMap.Flow += retLen
|
|
|
- // //sfMap.Site = *site
|
|
|
- // //sfMap.Channel = *channel
|
|
|
- // //sfMap.ModifyUser = *user
|
|
|
- // SpiderFlowMap.Store(key, sfMap)
|
|
|
- // }
|
|
|
- // } else {
|
|
|
- // SpiderFlowMap.Store(key, &SpiderFlow{
|
|
|
- // //Code: code,
|
|
|
- // Site: *site,
|
|
|
- // Channel: *channel,
|
|
|
- // Flow: retLen,
|
|
|
- // ModifyUser: *user,
|
|
|
- // })
|
|
|
- // }
|
|
|
- //}
|
|
|
+ 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)
|
|
|
+ var retLen int64
|
|
|
+ ret = DownloadFile(&retLen, s.Downloader, url, method, util.GetTable(param), util.GetTable(head), mycookie, s.Encoding, s.Userproxy, ishttps, s.SCode, s.Timeout)
|
|
|
+ //流量统计
|
|
|
+ //if retLen > 0 {
|
|
|
+ // key := Today + "+" + code
|
|
|
+ // if sf, ok := SpiderFlowMap.Load(key); ok && sf != nil {
|
|
|
+ // if sfMap, ok := sf.(*SpiderFlow); ok {
|
|
|
+ // sfMap.Flow += retLen
|
|
|
+ // //sfMap.Site = *site
|
|
|
+ // //sfMap.Channel = *channel
|
|
|
+ // //sfMap.ModifyUser = *user
|
|
|
+ // SpiderFlowMap.Store(key, sfMap)
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // SpiderFlowMap.Store(key, &SpiderFlow{
|
|
|
+ // //Code: code,
|
|
|
+ // Site: *site,
|
|
|
+ // Channel: *channel,
|
|
|
+ // Flow: retLen,
|
|
|
+ // ModifyUser: *user,
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ //}
|
|
|
|
|
|
- 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:]
|
|
|
+ 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:]
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
//特殊处理中国招标投标公共服务平台异常附件过滤
|
|
@@ -303,6 +324,29 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
|
|
|
s.FileLastThreeTimes = append(s.FileLastThreeTimes, end)
|
|
|
return 5
|
|
|
}))
|
|
|
+ //下载、上传base64图片
|
|
|
+ s.L.SetGlobal("downloadBase64File", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
+ url := S.ToString(-3)
|
|
|
+ fileName := S.ToString(-2)
|
|
|
+ base64Img := S.ToString(-1)
|
|
|
+ if fileName == "" {
|
|
|
+ fileName = "文件下载"
|
|
|
+ }
|
|
|
+ fileName = fileName + ".jpg"
|
|
|
+ i := strings.Index(base64Img, ",")
|
|
|
+ dec := base64.NewDecoder(base64.StdEncoding, strings.NewReader(base64Img[i+1:]))
|
|
|
+ ret, err := io.ReadAll(dec)
|
|
|
+ name, size, ftype, fid := "", "", "", ""
|
|
|
+ if err == nil && len(ret) > 0 {
|
|
|
+ url, name, size, ftype, fid = util.UploadFile(s.SCode, fileName, url, ret)
|
|
|
+ }
|
|
|
+ S.Push(lua.LString(url))
|
|
|
+ S.Push(lua.LString(name))
|
|
|
+ S.Push(lua.LString(size))
|
|
|
+ S.Push(lua.LString(ftype))
|
|
|
+ S.Push(lua.LString(fid))
|
|
|
+ return 5
|
|
|
+ }))
|
|
|
//保存验证错误日志
|
|
|
s.L.SetGlobal("saveErrLog", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
code := S.ToString(-4)
|