mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 08:23:47 +01:00
rest, b2, onedrive: remove Absolute parameter from rest.Opts and replace with RootURL
This commit is contained in:
parent
5f70746d39
commit
384724fd11
20
b2/b2.go
20
b2/b2.go
@ -227,7 +227,7 @@ func errorHandler(resp *http.Response) error {
|
||||
// NewFs contstructs an Fs from the path, bucket:path
|
||||
func NewFs(name, root string) (fs.Fs, error) {
|
||||
if uploadCutoff < chunkSize {
|
||||
return nil, errors.Errorf("b2: upload cutoff must be less than chunk size %v - was %v", chunkSize, uploadCutoff)
|
||||
return nil, errors.Errorf("b2: upload cutoff (%v) must be greater than or equal to chunk size (%v)", uploadCutoff, chunkSize)
|
||||
}
|
||||
if chunkSize < minChunkSize {
|
||||
return nil, errors.Errorf("b2: chunk size can't be less than %v - was %v", minChunkSize, chunkSize)
|
||||
@ -303,9 +303,9 @@ func (f *Fs) authorizeAccount() error {
|
||||
f.authMu.Lock()
|
||||
defer f.authMu.Unlock()
|
||||
opts := rest.Opts{
|
||||
Absolute: true,
|
||||
Method: "GET",
|
||||
Path: f.endpoint + "/b2api/v1/b2_authorize_account",
|
||||
Path: "/b2api/v1/b2_authorize_account",
|
||||
RootURL: f.endpoint,
|
||||
UserName: f.account,
|
||||
Password: f.key,
|
||||
ExtraHeaders: map[string]string{"Authorization": ""}, // unset the Authorization for this request
|
||||
@ -1118,10 +1118,9 @@ var _ io.ReadCloser = &openFile{}
|
||||
// Open an object for read
|
||||
func (o *Object) Open(options ...fs.OpenOption) (in io.ReadCloser, err error) {
|
||||
opts := rest.Opts{
|
||||
Method: "GET",
|
||||
Absolute: true,
|
||||
Path: o.fs.info.DownloadURL,
|
||||
Options: options,
|
||||
Method: "GET",
|
||||
RootURL: o.fs.info.DownloadURL,
|
||||
Options: options,
|
||||
}
|
||||
// Download by id if set otherwise by name
|
||||
if o.id != "" {
|
||||
@ -1322,10 +1321,9 @@ func (o *Object) Update(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOptio
|
||||
// will be returned with the download.
|
||||
|
||||
opts := rest.Opts{
|
||||
Method: "POST",
|
||||
Absolute: true,
|
||||
Path: upload.UploadURL,
|
||||
Body: in,
|
||||
Method: "POST",
|
||||
RootURL: upload.UploadURL,
|
||||
Body: in,
|
||||
ExtraHeaders: map[string]string{
|
||||
"Authorization": upload.AuthorizationToken,
|
||||
"X-Bz-File-Name": urlEncode(o.fs.root + o.remote),
|
||||
|
@ -163,10 +163,9 @@ func (up *largeUpload) transferChunk(part int64, body []byte) error {
|
||||
// data arrived correctly. The same SHA1 checksum must be
|
||||
// passed to b2_finish_large_file.
|
||||
opts := rest.Opts{
|
||||
Method: "POST",
|
||||
Absolute: true,
|
||||
Path: upload.UploadURL,
|
||||
Body: fs.AccountPart(up.o, bytes.NewBuffer(body)),
|
||||
Method: "POST",
|
||||
RootURL: upload.UploadURL,
|
||||
Body: fs.AccountPart(up.o, bytes.NewBuffer(body)),
|
||||
ExtraHeaders: map[string]string{
|
||||
"Authorization": upload.AuthorizationToken,
|
||||
"X-Bz-Part-Number": fmt.Sprintf("%d", part),
|
||||
|
@ -393,8 +393,8 @@ OUTER:
|
||||
if result.NextLink == "" {
|
||||
break
|
||||
}
|
||||
opts.Path = result.NextLink
|
||||
opts.Absolute = true
|
||||
opts.Path = ""
|
||||
opts.RootURL = result.NextLink
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -564,8 +564,7 @@ func (f *Fs) waitForJob(location string, o *Object) error {
|
||||
for time.Now().Before(deadline) {
|
||||
opts := rest.Opts{
|
||||
Method: "GET",
|
||||
Path: location,
|
||||
Absolute: true,
|
||||
RootURL: location,
|
||||
IgnoreStatus: true, // Ignore the http status response since it seems to return valid info on 500 errors
|
||||
}
|
||||
var resp *http.Response
|
||||
@ -929,13 +928,11 @@ func (o *Object) createUploadSession() (response *api.CreateUploadResponse, err
|
||||
func (o *Object) uploadFragment(url string, start int64, totalSize int64, chunk io.ReadSeeker, chunkSize int64) (err error) {
|
||||
opts := rest.Opts{
|
||||
Method: "PUT",
|
||||
Path: url,
|
||||
Absolute: true,
|
||||
RootURL: url,
|
||||
ContentLength: &chunkSize,
|
||||
ContentRange: fmt.Sprintf("bytes %d-%d/%d", start, start+chunkSize-1, totalSize),
|
||||
Body: chunk,
|
||||
}
|
||||
fs.Debugf(o, "OPTS: %s", opts.ContentRange)
|
||||
var response api.UploadFragmentResponse
|
||||
var resp *http.Response
|
||||
err = o.fs.pacer.Call(func() (bool, error) {
|
||||
@ -950,8 +947,7 @@ func (o *Object) uploadFragment(url string, start int64, totalSize int64, chunk
|
||||
func (o *Object) cancelUploadSession(url string) (err error) {
|
||||
opts := rest.Opts{
|
||||
Method: "DELETE",
|
||||
Path: url,
|
||||
Absolute: true,
|
||||
RootURL: url,
|
||||
NoResponse: true,
|
||||
}
|
||||
var resp *http.Response
|
||||
|
25
rest/rest.go
25
rest/rest.go
@ -61,7 +61,8 @@ func (api *Client) SetErrorHandler(fn func(resp *http.Response) error) *Client {
|
||||
return api
|
||||
}
|
||||
|
||||
// SetRoot sets the default root URL
|
||||
// SetRoot sets the default RootURL. You can override this on a per
|
||||
// call basis using the RootURL field in Opts.
|
||||
func (api *Client) SetRoot(RootURL string) *Client {
|
||||
api.mu.Lock()
|
||||
defer api.mu.Unlock()
|
||||
@ -80,8 +81,7 @@ func (api *Client) SetHeader(key, value string) *Client {
|
||||
// Opts contains parameters for Call, CallJSON etc
|
||||
type Opts struct {
|
||||
Method string // GET, POST etc
|
||||
Path string // relative to RootURL unless Absolute set
|
||||
Absolute bool // Path is absolute - dont add RootURL
|
||||
Path string // relative to RootURL
|
||||
RootURL string // override RootURL passed into SetRoot()
|
||||
Body io.Reader
|
||||
NoResponse bool // set to close Body
|
||||
@ -147,19 +147,14 @@ func (api *Client) Call(opts *Opts) (resp *http.Response, err error) {
|
||||
if opts == nil {
|
||||
return nil, errors.New("call() called with nil opts")
|
||||
}
|
||||
var url string
|
||||
if opts.Absolute {
|
||||
url = opts.Path
|
||||
} else {
|
||||
url = api.rootURL
|
||||
if opts.RootURL != "" {
|
||||
url = opts.RootURL
|
||||
}
|
||||
if url == "" {
|
||||
return nil, errors.New("RootURL not set")
|
||||
}
|
||||
url += opts.Path
|
||||
url := api.rootURL
|
||||
if opts.RootURL != "" {
|
||||
url = opts.RootURL
|
||||
}
|
||||
if url == "" {
|
||||
return nil, errors.New("RootURL not set")
|
||||
}
|
||||
url += opts.Path
|
||||
if opts.Parameters != nil && len(opts.Parameters) > 0 {
|
||||
url += "?" + opts.Parameters.Encode()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user