read token from config
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user