Skip to content
Snippets Groups Projects
Commit fe1550c2 authored by Travis Ralston's avatar Travis Ralston
Browse files

Update MSC4034 implementation

parent ed3a0a54
No related branches found
No related tags found
No related merge requests found
...@@ -10,30 +10,18 @@ import ( ...@@ -10,30 +10,18 @@ import (
) )
type PublicUsageResponse struct { type PublicUsageResponse struct {
StorageFree int64 `json:"org.matrix.msc4034.storage.free,omitempty"` StorageUsed int64 `json:"org.matrix.msc4034.storage.used,omitempty"`
StorageFiles int64 `json:"org.matrix.msc4034.storage.files,omitempty"` StorageFiles int64 `json:"org.matrix.msc4034.storage.files,omitempty"`
} }
func PublicUsage(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} { func PublicUsage(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
storageUsed := int64(0) storageUsed := int64(0)
storageLimit := int64(0) current, err := quota.Current(rctx, user.UserId, quota.MaxBytes)
limit, err := quota.Limit(rctx, user.UserId, quota.MaxBytes)
if err != nil { if err != nil {
rctx.Log.Warn("Non-fatal error getting per-user quota limit (max bytes): ", err) rctx.Log.Warn("Non-fatal error getting per-user quota usage (max bytes @ now): ", err)
sentry.CaptureException(err) sentry.CaptureException(err)
} else if limit > 0 {
storageLimit = limit
}
if storageLimit > 0 {
current, err := quota.Current(rctx, user.UserId, quota.MaxBytes)
if err != nil {
rctx.Log.Warn("Non-fatal error getting per-user quota usage (max bytes @ now): ", err)
sentry.CaptureException(err)
} else {
storageUsed = current
}
} else { } else {
storageLimit = 0 storageUsed = current
} }
fileCount, err := quota.Current(rctx, user.UserId, quota.MaxCount) fileCount, err := quota.Current(rctx, user.UserId, quota.MaxCount)
...@@ -43,7 +31,7 @@ func PublicUsage(r *http.Request, rctx rcontext.RequestContext, user _apimeta.Us ...@@ -43,7 +31,7 @@ func PublicUsage(r *http.Request, rctx rcontext.RequestContext, user _apimeta.Us
} }
return &PublicUsageResponse{ return &PublicUsageResponse{
StorageFree: storageLimit - storageUsed, StorageUsed: storageUsed,
StorageFiles: fileCount, StorageFiles: fileCount,
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment