Fix download issues
This commit is contained in:
@@ -114,16 +114,14 @@ func (d *Downloader) downloadFromAPI(request *Request, buffer []byte, delay int6
|
||||
downloadURL := resp.Download
|
||||
req, err := http.NewRequest("GET", downloadURL, nil)
|
||||
if nil != err {
|
||||
d.log.Debugf("%v", err)
|
||||
d.log.Debugf("request init error: %v", err)
|
||||
return fmt.Errorf("could not create request object %s %s from API", request.file.Path, request.file.Link)
|
||||
}
|
||||
req.Header.Add("Range", fmt.Sprintf("bytes=%v-%v", request.offsetStart, request.offsetEnd-1))
|
||||
|
||||
d.log.Debugw("Sending HTTP Request %v", req)
|
||||
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if nil != err {
|
||||
d.log.Debugf("%v", err)
|
||||
d.log.Debugf("request error: %v", err)
|
||||
return fmt.Errorf("could not request object %s %s from API", request.file.Path, request.file.Link)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
@@ -139,8 +137,8 @@ func (d *Downloader) downloadFromAPI(request *Request, buffer []byte, delay int6
|
||||
}
|
||||
|
||||
n, err := io.ReadFull(reader, buffer[:res.ContentLength:cap(buffer)])
|
||||
if nil != err {
|
||||
d.log.Debugf("%v", err)
|
||||
if nil != err && err != io.ErrUnexpectedEOF {
|
||||
d.log.Debugf("response read error: %v", err)
|
||||
return fmt.Errorf("could not read objects %s %s API response", request.file.Path, request.file.Link)
|
||||
}
|
||||
d.log.Debugf("Downloaded %v bytes of %s %s", n, request.file.Path, request.file.Link)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package chunk
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
@@ -144,7 +144,12 @@ func (m *Manager) GetChunk(object *torrent.File, offset, size int64) ([]byte, er
|
||||
}
|
||||
|
||||
func buildRequestID(object *torrent.File, offset int64) (id RequestID) {
|
||||
hex.Decode(id[:], []byte(object.Link))
|
||||
fileID := object.Link
|
||||
if fileID == "" {
|
||||
fileID = object.Path
|
||||
}
|
||||
hash := sha256.Sum256([]byte(fileID))
|
||||
copy(id[:16], hash[:16])
|
||||
binary.BigEndian.PutUint64(id[16:], uint64(offset))
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user