From ee9684e60fc665efb2ea3d523173863d128c7669 Mon Sep 17 00:00:00 2001 From: Gourav T Date: Mon, 24 Jan 2022 08:12:36 +0530 Subject: [PATCH] fichier: implemented about functionality --- backend/fichier/fichier.go | 26 ++++++++++++++++++++++++++ backend/fichier/structs.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/backend/fichier/fichier.go b/backend/fichier/fichier.go index 3dcac4d5d..1af73bdc2 100644 --- a/backend/fichier/fichier.go +++ b/backend/fichier/fichier.go @@ -514,6 +514,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) { + opts := rest.Opts{ + Method: "POST", + Path: "/user/info.cgi", + ContentType: "application/json", + } + var account_info AccountInfo + var resp *http.Response + err = f.pacer.Call(func() (bool, error) { + resp, err = f.rest.CallJSON(ctx, &opts, nil, &account_info) + return shouldRetry(ctx, resp, err) + }) + if err != nil { + return nil, fmt.Errorf("failed to read user info: %w", err) + } + + // FIXME max upload size would be useful to use in Update + usage = &fs.Usage{ + Used: fs.NewUsageValue(account_info.ColdStorage), // bytes in use + Total: fs.NewUsageValue(account_info.AvailableColdStorage), // bytes total + Free: fs.NewUsageValue(account_info.AvailableColdStorage - account_info.ColdStorage), // bytes free + } + return usage, nil +} + // PublicLink adds a "readable by anyone with link" permission on the given file or folder. func (f *Fs) PublicLink(ctx context.Context, remote string, expire fs.Duration, unlink bool) (string, error) { o, err := f.NewObject(ctx, remote) diff --git a/backend/fichier/structs.go b/backend/fichier/structs.go index ab40fb25a..7868066e8 100644 --- a/backend/fichier/structs.go +++ b/backend/fichier/structs.go @@ -182,3 +182,33 @@ type FoldersList struct { Status string `json:"Status"` SubFolders []Folder `json:"sub_folders"` } + +type AccountInfo struct { + StatsDate string `json:"stats_date"` + MailRM string `json:"mail_rm"` + DefaultQuota int64 `json:"default_quota"` + UploadForbidden string `json:"upload_forbidden"` + PageLimit int `json:"page_limit"` + ColdStorage int64 `json:"cold_storage"` + Status string `json:"status"` + UseCDN string `json:"use_cdn"` + AvailableColdStorage int64 `json:"available_cold_storage"` + DefaultPort string `json:"default_port"` + DefaultDomain int `json:"default_domain"` + Email string `json:"email"` + DownloadMenu string `json:"download_menu"` + FTPDID int `json:"ftp_did"` + DefaultPortFiles string `json:"default_port_files"` + FTPReport string `json:"ftp_report"` + OverQuota int64 `json:"overquota"` + AvailableStorage int64 `json:"available_storage"` + CDN string `json:"cdn"` + Offer string `json:"offer"` + SubscriptionEnd string `json:"subscription_end"` + TFA string `json:"2fa"` + AllowedColdStorage int64 `json:"allowed_cold_storage"` + HotStorage int64 `json:"hot_storage"` + DefaultColdStorageQuota int64 `json:"default_cold_storage_quota"` + FTPMode string `json:"ftp_mode"` + RUReport string `json:"ru_report"` +}