calculate quota stage

This commit is contained in:
Michael Barz
2021-10-15 11:13:57 +02:00
parent b155569c95
commit fabed476f7
2 changed files with 22 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
Enhancement: Report quota states
When listing the available spaces via the GraphAPI we now return quota states to make it easier for the clients to add visual indicators.
https://github.com/owncloud/ocis/pull/2628

View File

@@ -452,10 +452,27 @@ func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.Storage
Total: &total,
Used: &used,
}
state := calculateQuotaState(total, used)
qta.State = &state
return qta, nil
}
func calculateQuotaState(total int64, used int64) (state string) {
percent := (float64(used) / float64(total)) * 100
switch {
case percent <= float64(75):
return "normal"
case percent <= float64(90):
return "nearing"
case percent <= float64(99):
return "critical"
default:
return "exceeded"
}
}
func getQuota(quota *msgraph.Quota, defaultQuota string) *provider.Quota {
switch {
case quota != nil && quota.Total != nil:
@@ -471,5 +488,4 @@ func getQuota(quota *msgraph.Quota, defaultQuota string) *provider.Quota {
default:
return nil
}
}