package downloader
import (
"context"
"strconv"
"github.com/go-faster/errors"
"github.com/gotd/td/tg"
)
type RedirectError struct {
Redirect *tg .UploadFileCDNRedirect
}
func (r *RedirectError ) Error () string {
return "redirect to CDN DC " + strconv .Itoa (r .Redirect .DCID )
}
type master struct {
client Client
precise bool
allowCDN bool
retryHandler RetryHandler
location tg .InputFileLocationClass
}
var _ schema = master {}
func (c master ) reportRetry (operation string , attempt int , err error ) {
if attempt < 1 || err == nil || c .retryHandler == nil {
return
}
c .retryHandler (RetryEvent {
Operation : operation ,
Attempt : attempt ,
Err : err ,
})
}
func (c master ) Chunk (ctx context .Context , offset int64 , limit int ) (chunk , error ) {
req := &tg .UploadGetFileRequest {
Offset : offset ,
Limit : limit ,
Location : c .location ,
}
req .SetCDNSupported (c .allowCDN )
req .SetPrecise (c .precise )
r , err := c .client .UploadGetFile (ctx , req )
if err != nil {
return chunk {}, err
}
switch result := r .(type ) {
case *tg .UploadFile :
return chunk {data : result .Bytes , tag : result .Type }, nil
case *tg .UploadFileCDNRedirect :
return chunk {}, &RedirectError {Redirect : result }
default :
return chunk {}, errors .Errorf ("unexpected type %T" , r )
}
}
func (c master ) Hashes (ctx context .Context , offset int64 ) ([]tg .FileHash , error ) {
return c .client .UploadGetFileHashes (ctx , &tg .UploadGetFileHashesRequest {
Location : c .location ,
Offset : offset ,
})
}
The pages are generated with Golds v0.8.4 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .