Proper logging
This commit is contained in:
@@ -81,7 +81,46 @@ func UnrestrictLink(accessToken, link string) (*UnrestrictResponse, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response, nil
|
||||
if canFetchFirstByte(response.Download) {
|
||||
return &response, nil
|
||||
}
|
||||
return nil, fmt.Errorf("can't fetch first byte")
|
||||
}
|
||||
|
||||
func canFetchFirstByte(url string) bool {
|
||||
// Create a new HTTP request
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// Set the Range header to request only the first byte
|
||||
req.Header.Set("Range", "bytes=0-0")
|
||||
|
||||
// Execute the request
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// If server supports partial content
|
||||
if resp.StatusCode == http.StatusPartialContent {
|
||||
buffer := make([]byte, 1)
|
||||
_, err := resp.Body.Read(buffer)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// GetTorrents returns all torrents, paginated
|
||||
|
||||
Reference in New Issue
Block a user