Skip to content

Commit

Permalink
提升稳定性,增加成功几率
Browse files Browse the repository at this point in the history
  • Loading branch information
user1121114685 committed Mar 29, 2023
1 parent c0738bc commit 7c77af3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"
)

var Agent = elevengo.New(option.CooldownOption{Min: 100, Max: 1003})
var Agent = elevengo.New(option.CooldownOption{Min: 120, Max: 1003})

func Login() {

Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log"
"os"
"regexp"
"strings"
"time"
)

Expand Down Expand Up @@ -84,6 +85,14 @@ func main() {
time.Sleep(2 * time.Second)
continue
}
url = strings.ToLower(url)
_isHttp, _ := regexp.MatchString("^https?://", url)
if !_isHttp {
// 不是数字 说明输入有误
fmt.Println("url 不正确 应该包含 http:// 或者 https://")
time.Sleep(2 * time.Second)
continue
}
if cid == "" || url == "" || shareCid == "" {
// 不是数字 说明输入有误
fmt.Println("信息没有输入完整,请重新检查。")
Expand Down
35 changes: 27 additions & 8 deletions receiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Import(dirid, url, shareCid string) {
}
break
}
wg := NewImporter(5)
wg := NewImporter(4)
importFileForDir(firstDirID, url, &tickets, wg)
wg.producerWaitGroupPool.Wait()
close(wg.taskChannel)
Expand Down Expand Up @@ -70,6 +70,7 @@ func importFileForDir(dirid, url string, tickets *utils.FileList, wg *importer)
if ticket.IsDir {
var id string
var err error
var _name = ticket.ImportTicket.FileName
for i := 0; i < 20; i++ {
// 已经导入的部分 直接赋值
if ticket.MakeDIrCid != "" {
Expand All @@ -80,7 +81,7 @@ func importFileForDir(dirid, url string, tickets *utils.FileList, wg *importer)
if err != nil && err.Error() == "target already exists" {
// target already exists
//log.Println("创建 第一级目录失败", err)
ticket.ImportTicket.FileName = ticket.ImportTicket.FileName + "_" + strconv.Itoa(i)
ticket.ImportTicket.FileName = _name + "_" + strconv.Itoa(i)
continue
}
// 没有新建文件夹的ID 新建一次文件夹并赋值
Expand Down Expand Up @@ -109,7 +110,8 @@ func importFileForDir(dirid, url string, tickets *utils.FileList, wg *importer)
err := login.Agent.Import(dirid, &ticket.ImportTicket)
ticket.IsImport = true
if err != nil {
if ie, ok := err.(*elevengo.ErrImportNeedCheck); ok {
ie, ok := err.(*elevengo.ErrImportNeedCheck)
if ok {
signValue := getCalculateSignValue(url, ticket.PickCode, ie.SignRange)
if signValue != "invalid" {
ticket.ImportTicket.SignKey = ie.SignKey
Expand All @@ -125,6 +127,10 @@ func importFileForDir(dirid, url string, tickets *utils.FileList, wg *importer)
reImportFileForDir(dirid, url, ticket.PickCode, ticket.ImportTicket)
continue
}
//log.Println(err)
// 失败重新导入增加那么一丝丝可能性 能降低失败机率
reImportFileForDir(dirid, url, ticket.PickCode, ticket.ImportTicket)
continue
}
log.Println("导入成功 " + ticket.ImportTicket.FileName)

Expand All @@ -133,13 +139,25 @@ func importFileForDir(dirid, url string, tickets *utils.FileList, wg *importer)
}

func reImportFileForDir(dirid, url, pickCode string, ImportTicket elevengo.ImportTicket) {

var err error
for i := 0; i < 5; i++ {
time.Sleep(1 * time.Second)

iport_ticket := ImportTicket
err := login.Agent.Import(dirid, &iport_ticket)
iport_ticket.SignKey = ""
iport_ticket.SignValue = ""
err = login.Agent.Import(dirid, &iport_ticket)
if err != nil {
if ie, ok := err.(*elevengo.ErrImportNeedCheck); ok {
if err.Error() == "sig invalid" {
time.Sleep(5 * time.Second)
continue
}
if err.Error() == "invalid ec data" {
log.Println("速度过快,需要等待130秒....")
time.Sleep(130 * time.Second)
continue
}
ie, ok := err.(*elevengo.ErrImportNeedCheck)
if ok {
signValue := getCalculateSignValue(url, pickCode, ie.SignRange)
if signValue != "invalid" {
iport_ticket.SignKey = ie.SignKey
Expand All @@ -156,11 +174,12 @@ func reImportFileForDir(dirid, url, pickCode string, ImportTicket elevengo.Impor
}
continue
}
continue
}
log.Println("导入成功 " + iport_ticket.FileName)
return
}
log.Println("导入失败 " + ImportTicket.FileName)
log.Println("导入失败 "+ImportTicket.FileName, err)
}

func getFileList(url string, tickets *utils.FileList) {
Expand Down

0 comments on commit 7c77af3

Please sign in to comment.