Feat/Search support (#25)
* new: feat: add search support with meilisearch * new: feat: add search interface * new: feat: add new audio mappings * chg: fix: add meilisearch docs * chg: fix: lint issues * chg: feat: add br flag * chg: fix: use the same user agent * chg: fix: bludv (again) * chg: fix: lint issue
This commit is contained in:
@@ -10,6 +10,8 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/felipemarinho97/torrent-indexer/utils"
|
||||
)
|
||||
|
||||
type FlareSolverr struct {
|
||||
@@ -243,8 +245,15 @@ func (f *FlareSolverr) Get(_url string) (io.ReadCloser, error) {
|
||||
return nil, fmt.Errorf("under attack")
|
||||
}
|
||||
|
||||
// check if the response is valid HTML
|
||||
if !utils.IsValidHTML(response.Solution.Response) {
|
||||
fmt.Printf("[FlareSolverr] Invalid HTML response from %s\n", _url)
|
||||
response.Solution.Response = ""
|
||||
}
|
||||
|
||||
// If the response body is empty but cookies are present, make a new request
|
||||
if response.Solution.Response == "" && len(response.Solution.Cookies) > 0 {
|
||||
fmt.Printf("[FlareSolverr] Making a new request to %s with cookies\n", _url)
|
||||
// Create a new request with cookies
|
||||
client := &http.Client{}
|
||||
cookieJar, err := cookiejar.New(&cookiejar.Options{})
|
||||
@@ -268,13 +277,22 @@ func (f *FlareSolverr) Get(_url string) (io.ReadCloser, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// use the same user returned by the FlareSolverr
|
||||
secondReq.Header.Set("User-Agent", response.Solution.UserAgent)
|
||||
|
||||
secondResp, err := client.Do(secondReq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
respByte := new(bytes.Buffer)
|
||||
_, err = respByte.ReadFrom(secondResp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Return the body of the second request
|
||||
return secondResp.Body, nil
|
||||
return io.NopCloser(bytes.NewReader(respByte.Bytes())), nil
|
||||
}
|
||||
|
||||
// Return the original response body
|
||||
|
||||
Reference in New Issue
Block a user