mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-05 03:40:01 -06:00
calculate quota stage
This commit is contained in:
5
changelog/unreleased/report-quota-states.md
Normal file
5
changelog/unreleased/report-quota-states.md
Normal 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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user