|
@@ -208,6 +208,62 @@ func DownloadFile(downloaderid, url, method string, reqparam, head map[string]in
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func NewDownloadFile(downloaderid, url, method string, reqparam, head map[string]interface{}, mycookie []*http.Cookie, encoding string, useproxy, ishttps bool, code string, timeout int64, noredirect bool) []byte {
|
|
|
+ defer mu.Catch()
|
|
|
+ timeout = timeout * 10
|
|
|
+ msgid := mu.UUID(8)
|
|
|
+ if len(head) < 1 {
|
|
|
+ l := len(agent.UserAgents["common"])
|
|
|
+ r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
+ head["User-Agent"] = agent.UserAgents["common"][r.Intn(l)]
|
|
|
+ }
|
|
|
+ var ret []byte
|
|
|
+ var err error
|
|
|
+ if downloaderid == "" {
|
|
|
+ ret, err = MsclientFile.Call("", msgid, mu.SERVICE_DOWNLOAD, mu.SENDTO_TYPE_RAND_RECIVER, map[string]interface{}{
|
|
|
+ "url": url,
|
|
|
+ "method": method,
|
|
|
+ "head": head,
|
|
|
+ "reqparam": reqparam,
|
|
|
+ "cookie": mycookie,
|
|
|
+ "encoding": encoding,
|
|
|
+ "useproxy": useproxy,
|
|
|
+ "ishttps": ishttps,
|
|
|
+ "new": true,
|
|
|
+ "noredirect": noredirect,
|
|
|
+ }, timeout)
|
|
|
+ } else {
|
|
|
+ if isAvailableFile(downloaderid) {
|
|
|
+ ret, err = MsclientFile.Call(downloaderid, msgid, mu.SERVICE_DOWNLOAD, mu.SENDTO_TYPE_P2P, map[string]interface{}{
|
|
|
+ "url": url,
|
|
|
+ "method": method,
|
|
|
+ "head": head,
|
|
|
+ "reqparam": reqparam,
|
|
|
+ "cookie": mycookie,
|
|
|
+ "encoding": encoding,
|
|
|
+ "useproxy": useproxy,
|
|
|
+ "ishttps": ishttps,
|
|
|
+ "new": true,
|
|
|
+ "noredirect": noredirect,
|
|
|
+ }, timeout)
|
|
|
+ } else {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if err != nil {
|
|
|
+ str := code + "方法DownloadFile,url:" + url + ",err:" + err.Error()
|
|
|
+ log.Println(str, timeout)
|
|
|
+ }
|
|
|
+ tmp := map[string]interface{}{}
|
|
|
+ json.Unmarshal(ret, &tmp)
|
|
|
+ if v, ok := tmp["code"].(string); ok && v == "200" {
|
|
|
+ bs, _ := base64.StdEncoding.DecodeString(tmp["content"].(string))
|
|
|
+ return bs
|
|
|
+ } else {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func DownloadFile_back(downloaderid, url, method string, reqparam, head map[string]interface{}, mycookie []*http.Cookie, encoding string, useproxy, ishttps bool, code string, timeout int64) []byte {
|
|
|
defer mu.Catch()
|
|
|
msgid := mu.UUID(8)
|