-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run V1 detector, bulk court app type
- Loading branch information
Showing
14 changed files
with
335 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package trialdownloader | ||
|
||
import "net/http" | ||
|
||
func NewDownloader(client *http.Client, baseUrl string) Downloader { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package trialdownloader | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"sync" | ||
|
||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
type CourtData struct { | ||
Domain string `json:"domain"` | ||
AppTypes []AppType `json:"app_types"` | ||
} | ||
|
||
const ( | ||
AppTypeV1 AppType = "V1:url/wokanda,I" | ||
) | ||
|
||
func Detect(ctx context.Context, client *http.Client, baseUrl string) (result []AppType) { | ||
detectors := [](func(ctx context.Context, client *http.Client, baseUrl string) (bool, AppType)){ | ||
detectV1, | ||
} | ||
|
||
var resultMu sync.Mutex | ||
|
||
eg, ctx := errgroup.WithContext(ctx) | ||
for _, d := range detectors { | ||
eg.Go(func() error { | ||
if found, typ := d(ctx, client, baseUrl); found { | ||
resultMu.Lock() | ||
result = append(result, typ) | ||
resultMu.Unlock() | ||
} | ||
return nil | ||
}) | ||
} | ||
|
||
eg.Wait() | ||
|
||
return | ||
} | ||
|
||
func DetectBulk(ctx context.Context, client *http.Client, domains []string) []CourtData { | ||
courts := make([]CourtData, len(domains)) | ||
eg, taskCtx := errgroup.WithContext(ctx) | ||
|
||
for i, domain := range domains { | ||
eg.Go(func() error { | ||
court := CourtData{ | ||
Domain: domain, | ||
AppTypes: append(make([]AppType, 0), Detect(taskCtx, client, domain)...), | ||
} | ||
courts[i] = court | ||
return nil | ||
}) | ||
} | ||
|
||
eg.Wait() | ||
return courts | ||
} | ||
|
||
func detectV1(ctx context.Context, client *http.Client, baseUrl string) (found bool, typ AppType) { | ||
typ = AppTypeV1 | ||
page, err := getOne(ctx, client, fmt.Sprintf("https://%v/wokanda", baseUrl)) | ||
if err != nil { | ||
return | ||
} | ||
|
||
found = bytes.Contains(page, []byte(`<form action="index.php" method="GET" class="cases-form">`)) && | ||
bytes.Contains(page, []byte(`<input name="p" type="hidden" value="cases"`)) && | ||
bytes.Contains(page, []byte(`<input name="action" type="hidden" value="search"`)) | ||
|
||
return | ||
} |
Oops, something went wrong.