Skip to content

Commit

Permalink
close #2
Browse files Browse the repository at this point in the history
  • Loading branch information
gyyyy committed Mar 11, 2021
1 parent 4e800d2 commit e35840b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
62 changes: 48 additions & 14 deletions zoomeye/zoomeye.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (z *ZoomEye) DorkSearch(dork string, page int, resource string, facet strin
func (z *ZoomEye) conMPSearch(dork string, maxPage int, resource string, facet string) (map[int]*SearchResult, error) {
var (
results = make(map[int]*SearchResult)
ch = make(chan map[string]interface{}, maxPage)
ch = make(chan map[string]interface{}, maxPage-1)
ctx, cancel = context.WithCancel(context.Background())
)
defer close(ch)
Expand All @@ -175,10 +175,10 @@ func (z *ZoomEye) conMPSearch(dork string, maxPage int, resource string, facet s
wg sync.WaitGroup
groupSize = 20
)
if maxPage < 20 {
groupSize = maxPage
if maxPage < 21 {
groupSize = maxPage - 1
}
var currPage int32
var currPage int32 = 1
for i := 0; i < groupSize; i++ {
wg.Add(1)
go func() {
Expand Down Expand Up @@ -244,19 +244,53 @@ func (z *ZoomEye) MultiPageSearch(dork string, maxPage int, resource string, fac
if maxPage <= 0 {
maxPage = 1
}
if maxPage >= 5 {
return z.conMPSearch(dork, maxPage, resource, facet)
info, err := z.ResourcesInfo()
if err != nil {
return nil, err
}
var (
results = make(map[int]*SearchResult)
err error
)
for i := 0; i < maxPage; i++ {
allowPage := info.Resources.Search / 20
if info.Resources.Search%20 > 0 {
allowPage++
}
results := make(map[int]*SearchResult)
if allowPage > 0 {
res, err := z.DorkSearch(dork, 1, resource, facet)
if err != nil {
return nil, err
}
results[1] = res
n := int(res.Total / 20)
if res.Total%20 > 0 {
n++
}
if n < allowPage {
allowPage = n
}
}
if maxPage > allowPage {
maxPage = allowPage
}
if maxPage > 5 {
corResults, err := z.conMPSearch(dork, maxPage, resource, facet)
if err != nil {
if len(results) > 0 {
return results, nil
}
return nil, err
}
for k, v := range results {
if _, ok := corResults[k]; !ok {
corResults[k] = v
}
}
return corResults, nil
}
for i := 1; i < maxPage; i++ {
var (
page = i + 1
res, err = z.DorkSearch(dork, page, resource, facet)
page = i + 1
res *SearchResult
)
if err != nil {
if res, err = z.DorkSearch(dork, page, resource, facet); err != nil {
break
}
results[page] = res
Expand Down
4 changes: 2 additions & 2 deletions zoomeye/zoomeye_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestMultiPageSearch(t *testing.T) {
if err != nil || (len(results) == 0) {
t.FailNow()
}
t.Log(results[1].Total, results[1].Type)
t.Log(results[1].Total, results[1].Type, len(results))
}

func TestMultiToOneSearch(t *testing.T) {
Expand All @@ -73,7 +73,7 @@ func TestMultiToOneSearch(t *testing.T) {
if err != nil || (len(result.Matches) != maxPage*20) {
t.FailNow()
}
t.Log(result.Total, result.Type)
t.Log(result.Total, result.Type, len(result.Matches))
}

func TestFilter(t *testing.T) {
Expand Down

0 comments on commit e35840b

Please sign in to comment.