Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

box: implement About to read size used - fixes #4264

Nick Craig-Wood9db8ecbc3220
diff --git a/backend/box/api/types.go b/backend/box/api/types.go
index a6cd39b8d..46a585e09 100644
--- a/backend/box/api/types.go
+++ b/backend/box/api/types.go
@@ -222,3 +222,23 @@ type AppAuth struct {
PrivateKey string `json:"privateKey"`
Passphrase string `json:"passphrase"`
}
+
+// User is returned from /users/me
+type User struct {
+ Type string `json:"type"`
+ ID string `json:"id"`
+ Name string `json:"name"`
+ Login string `json:"login"`
+ CreatedAt time.Time `json:"created_at"`
+ ModifiedAt time.Time `json:"modified_at"`
+ Language string `json:"language"`
+ Timezone string `json:"timezone"`
+ SpaceAmount int64 `json:"space_amount"`
+ SpaceUsed int64 `json:"space_used"`
+ MaxUploadSize int64 `json:"max_upload_size"`
+ Status string `json:"status"`
+ JobTitle string `json:"job_title"`
+ Phone string `json:"phone"`
+ Address string `json:"address"`
+ AvatarURL string `json:"avatar_url"`
+}
diff --git a/backend/box/box.go b/backend/box/box.go
index 279fc55db..b98c913ea 100644
--- a/backend/box/box.go
+++ b/backend/box/box.go
@@ -883,6 +883,29 @@ func (f *Fs) move(ctx context.Context, endpoint, id, leaf, directoryID string) (
return info, nil
}
+// About gets quota information
+func (f *Fs) About(ctx context.Context) (usage *fs.Usage, err error) {
+ opts := rest.Opts{
+ Method: "GET",
+ Path: "/users/me",
+ }
+ var user api.User
+ var resp *http.Response
+ err = f.pacer.Call(func() (bool, error) {
+ resp, err = f.srv.CallJSON(ctx, &opts, nil, &user)
+ return shouldRetry(resp, err)
+ })
+ if err != nil {
+ return nil, errors.Wrap(err, "failed to read user info")
+ }
+ // FIXME max upload size would be useful to use in Update
+ usage = &fs.Usage{
+ Used: fs.NewUsageValue(user.SpaceUsed), // bytes in use
+ Total: fs.NewUsageValue(user.SpaceAmount), // bytes total
+ }
+ return usage, nil
+}
+
// Move src to this remote using server side move operations.
//
// This is stored with the remote path given
@@ -1274,6 +1297,7 @@ var (
_ fs.Purger = (*Fs)(nil)
_ fs.PutStreamer = (*Fs)(nil)
_ fs.Copier = (*Fs)(nil)
+ _ fs.Abouter = (*Fs)(nil)
_ fs.Mover = (*Fs)(nil)
_ fs.DirMover = (*Fs)(nil)
_ fs.DirCacheFlusher = (*Fs)(nil)