mirror of
https://github.com/gilbertchen/duplicacy
synced 2025-12-14 23:33:18 +00:00
cleanup, simplified ListFileNames invoke of "call"
This commit is contained in:
@@ -203,7 +203,7 @@ type B2AuthorizeAccountOutput struct {
|
|||||||
|
|
||||||
func (client *B2Client) AuthorizeAccount() (err error) {
|
func (client *B2Client) AuthorizeAccount() (err error) {
|
||||||
|
|
||||||
readCloser, _, _, err := client.call(B2AuthorizationURL, http.MethodPost, make(map[string]string), make(map[string]string))
|
readCloser, _, _, err := client.call(B2AuthorizationURL, http.MethodPost, nil, make(map[string]string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -237,7 +237,7 @@ func (client *B2Client) FindBucket(bucketName string) (err error) {
|
|||||||
|
|
||||||
url := client.APIURL + "/b2api/v1/b2_list_buckets"
|
url := client.APIURL + "/b2api/v1/b2_list_buckets"
|
||||||
|
|
||||||
readCloser, _, _, err := client.call(url, http.MethodPost, make(map[string]string), input)
|
readCloser, _, _, err := client.call(url, http.MethodPost, nil, input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -299,11 +299,13 @@ func (client *B2Client) ListFileNames(startFileName string, singleFile bool, inc
|
|||||||
input["bucketId"] = client.BucketID
|
input["bucketId"] = client.BucketID
|
||||||
input["startFileName"] = startFileName
|
input["startFileName"] = startFileName
|
||||||
input["maxFileCount"] = maxFileCount
|
input["maxFileCount"] = maxFileCount
|
||||||
inputMapBool := true
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
url := client.APIURL + "/b2api/v1/b2_list_file_names"
|
url := client.APIURL + "/b2api/v1/b2_list_file_names"
|
||||||
requestHeaders := map[string]string{}
|
requestHeaders := map[string]string{}
|
||||||
|
requestMethod := http.MethodPost
|
||||||
|
var requestInput interface{}
|
||||||
|
requestInput = input
|
||||||
if includeVersions {
|
if includeVersions {
|
||||||
url = client.APIURL + "/b2api/v1/b2_list_file_versions"
|
url = client.APIURL + "/b2api/v1/b2_list_file_versions"
|
||||||
} else if singleFile {
|
} else if singleFile {
|
||||||
@@ -311,16 +313,13 @@ func (client *B2Client) ListFileNames(startFileName string, singleFile bool, inc
|
|||||||
url = client.DownloadURL + "/file/" + client.BucketName + "/" + startFileName
|
url = client.DownloadURL + "/file/" + client.BucketName + "/" + startFileName
|
||||||
requestHeaders["Range"] = "bytes=0-0"
|
requestHeaders["Range"] = "bytes=0-0"
|
||||||
// HEAD request
|
// HEAD request
|
||||||
inputMapBool = false
|
requestMethod = http.MethodHead
|
||||||
|
requestInput = 0
|
||||||
}
|
}
|
||||||
var readCloser io.ReadCloser
|
var readCloser io.ReadCloser
|
||||||
var responseHeader http.Header
|
var responseHeader http.Header
|
||||||
var err error
|
var err error
|
||||||
if inputMapBool {
|
readCloser, responseHeader, _, err = client.call(url, requestMethod, requestHeaders, requestInput)
|
||||||
readCloser, responseHeader, _, err = client.call(url, http.MethodPost, requestHeaders, input)
|
|
||||||
} else {
|
|
||||||
readCloser, responseHeader, _, err = client.call(url, http.MethodHead, requestHeaders, 0)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -329,7 +328,7 @@ func (client *B2Client) ListFileNames(startFileName string, singleFile bool, inc
|
|||||||
|
|
||||||
output := B2ListFileNamesOutput{}
|
output := B2ListFileNamesOutput{}
|
||||||
|
|
||||||
if !inputMapBool && singleFile && !includeVersions {
|
if singleFile && !includeVersions {
|
||||||
// construct the B2Entry from the response headers of the download request
|
// construct the B2Entry from the response headers of the download request
|
||||||
fileID := responseHeader.Get("x-bz-file-id")
|
fileID := responseHeader.Get("x-bz-file-id")
|
||||||
fileName := responseHeader.Get("x-bz-file-name")
|
fileName := responseHeader.Get("x-bz-file-name")
|
||||||
|
|||||||
Reference in New Issue
Block a user