mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 18:04:55 +01:00
rest, b2, onedrive: remove Absolute parameter from rest.Opts and replace with RootURL
This commit is contained in:
parent
5f70746d39
commit
384724fd11
12
b2/b2.go
12
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
|
||||
@ -1119,8 +1119,7 @@ var _ io.ReadCloser = &openFile{}
|
||||
func (o *Object) Open(options ...fs.OpenOption) (in io.ReadCloser, err error) {
|
||||
opts := rest.Opts{
|
||||
Method: "GET",
|
||||
Absolute: true,
|
||||
Path: o.fs.info.DownloadURL,
|
||||
RootURL: o.fs.info.DownloadURL,
|
||||
Options: options,
|
||||
}
|
||||
// Download by id if set otherwise by name
|
||||
@ -1323,8 +1322,7 @@ func (o *Object) Update(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOptio
|
||||
|
||||
opts := rest.Opts{
|
||||
Method: "POST",
|
||||
Absolute: true,
|
||||
Path: upload.UploadURL,
|
||||
RootURL: upload.UploadURL,
|
||||
Body: in,
|
||||
ExtraHeaders: map[string]string{
|
||||
"Authorization": upload.AuthorizationToken,
|
||||
|
@ -164,8 +164,7 @@ func (up *largeUpload) transferChunk(part int64, body []byte) error {
|
||||
// passed to b2_finish_large_file.
|
||||
opts := rest.Opts{
|
||||
Method: "POST",
|
||||
Absolute: true,
|
||||
Path: upload.UploadURL,
|
||||
RootURL: upload.UploadURL,
|
||||
Body: fs.AccountPart(up.o, bytes.NewBuffer(body)),
|
||||
ExtraHeaders: map[string]string{
|
||||
"Authorization": upload.AuthorizationToken,
|
||||
|
@ -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
|
||||
|
13
rest/rest.go
13
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,11 +147,7 @@ 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
|
||||
url := api.rootURL
|
||||
if opts.RootURL != "" {
|
||||
url = opts.RootURL
|
||||
}
|
||||
@ -159,7 +155,6 @@ func (api *Client) Call(opts *Opts) (resp *http.Response, err error) {
|
||||
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