From b1b4c7f27b291a5eb383d0f5bd6bfcafd23e6037 Mon Sep 17 00:00:00 2001 From: quiescens Date: Wed, 18 Sep 2024 02:20:42 +1000 Subject: [PATCH] opendrive: add about support to backend --- backend/opendrive/opendrive.go | 27 +++++++++++++++++++++++++++ backend/opendrive/types.go | 7 +++++++ docs/content/overview.md | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/backend/opendrive/opendrive.go b/backend/opendrive/opendrive.go index d73933980..7a5ec560b 100644 --- a/backend/opendrive/opendrive.go +++ b/backend/opendrive/opendrive.go @@ -404,6 +404,32 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, return dstObj, nil } +// About gets quota information +func (f *Fs) About(ctx context.Context) (usage *fs.Usage, err error) { + var uInfo usersInfoResponse + var resp *http.Response + + err = f.pacer.Call(func() (bool, error) { + opts := rest.Opts{ + Method: "GET", + Path: "/users/info.json/" + f.session.SessionID, + } + resp, err = f.srv.CallJSON(ctx, &opts, nil, &uInfo) + return f.shouldRetry(ctx, resp, err) + }) + + if err != nil { + return nil, err + } + + usage = &fs.Usage{ + Used: fs.NewUsageValue(uInfo.StorageUsed), + Total: fs.NewUsageValue(uInfo.MaxStorage * 1024 * 1024), // MaxStorage appears to be in MB + Free: fs.NewUsageValue(uInfo.MaxStorage*1024*1024 - uInfo.StorageUsed), + } + return usage, nil +} + // Move src to this remote using server-side move operations. // // This is stored with the remote path given. @@ -1147,6 +1173,7 @@ var ( _ fs.Mover = (*Fs)(nil) _ fs.DirMover = (*Fs)(nil) _ fs.DirCacheFlusher = (*Fs)(nil) + _ fs.Abouter = (*Fs)(nil) _ fs.Object = (*Object)(nil) _ fs.IDer = (*Object)(nil) _ fs.ParentIDer = (*Object)(nil) diff --git a/backend/opendrive/types.go b/backend/opendrive/types.go index d47a35628..fa897e0d7 100644 --- a/backend/opendrive/types.go +++ b/backend/opendrive/types.go @@ -231,3 +231,10 @@ type permissions struct { type uploadFileChunkReply struct { TotalWritten int64 `json:"TotalWritten"` } + +// usersInfoResponse describes OpenDrive users/info.json response +type usersInfoResponse struct { + // This response contains many other values but these are the only ones currently in use + StorageUsed int64 `json:"StorageUsed,string"` + MaxStorage int64 `json:"MaxStorage,string"` +} diff --git a/docs/content/overview.md b/docs/content/overview.md index a07f993ac..089889540 100644 --- a/docs/content/overview.md +++ b/docs/content/overview.md @@ -521,7 +521,7 @@ upon backend-specific capabilities. | Microsoft Azure Blob Storage | Yes | Yes | No | No | No | Yes | Yes | Yes | No | No | No | | Microsoft Azure Files Storage | No | Yes | Yes | Yes | No | No | Yes | Yes | No | Yes | Yes | | Microsoft OneDrive | Yes | Yes | Yes | Yes | Yes | Yes ⁵ | No | No | Yes | Yes | Yes | -| OpenDrive | Yes | Yes | Yes | Yes | No | No | No | No | No | No | Yes | +| OpenDrive | Yes | Yes | Yes | Yes | No | No | No | No | No | Yes | Yes | | OpenStack Swift | Yes ¹ | Yes | No | No | No | Yes | Yes | No | No | Yes | No | | Oracle Object Storage | No | Yes | No | No | Yes | Yes | Yes | Yes | No | No | No | | pCloud | Yes | Yes | Yes | Yes | Yes | No | No | No | Yes | Yes | Yes |