calculate quota stage
This commit is contained in:
@@ -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,
|
Total: &total,
|
||||||
Used: &used,
|
Used: &used,
|
||||||
}
|
}
|
||||||
|
state := calculateQuotaState(total, used)
|
||||||
|
qta.State = &state
|
||||||
|
|
||||||
return qta, nil
|
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 {
|
func getQuota(quota *msgraph.Quota, defaultQuota string) *provider.Quota {
|
||||||
switch {
|
switch {
|
||||||
case quota != nil && quota.Total != nil:
|
case quota != nil && quota.Total != nil:
|
||||||
@@ -471,5 +488,4 @@ func getQuota(quota *msgraph.Quota, defaultQuota string) *provider.Quota {
|
|||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user