read token from config

This commit is contained in:
Ben Sarmiento
2023-10-20 01:49:06 +02:00
parent 464f522fea
commit 0e442fc9be
9 changed files with 23 additions and 22 deletions

View File

@@ -81,10 +81,10 @@ func UnrestrictLink(accessToken, link string) (*UnrestrictResponse, error) {
return nil, err
}
if canFetchFirstByte(response.Download) {
return &response, nil
if !canFetchFirstByte(response.Download) {
return nil, fmt.Errorf("can't fetch first byte")
}
return nil, fmt.Errorf("can't fetch first byte")
return &response, nil
}
func canFetchFirstByte(url string) bool {
@@ -108,19 +108,14 @@ func canFetchFirstByte(url string) bool {
if resp.StatusCode == http.StatusPartialContent {
buffer := make([]byte, 1)
_, err := resp.Body.Read(buffer)
if err != nil {
return false
}
return true
return err == nil
}
// If server doesn't support partial content, try reading the first byte and immediately close
buffer := make([]byte, 1)
_, err = io.ReadFull(resp.Body, buffer)
if err != nil {
return false
}
return true
_, err = resp.Body.Read(buffer)
resp.Body.Close() // Close immediately after reading
return err == nil
}
// GetTorrents returns all torrents, paginated