databag/net/server/internal/api_getAccountStatus.go

36 lines
843 B
Go
Raw Normal View History

2022-03-08 21:31:04 +00:00
package databag
import (
2022-07-22 19:28:14 +00:00
"databag/internal/store"
"net/http"
2022-03-08 21:31:04 +00:00
)
2022-07-25 19:48:57 +00:00
//GetAccountStatus retrieves account state values
2022-03-08 21:31:04 +00:00
func GetAccountStatus(w http.ResponseWriter, r *http.Request) {
2022-07-22 19:28:14 +00:00
account, code, err := ParamAgentToken(r, true)
if err != nil {
ErrResponse(w, code, err)
return
}
var assets []store.Asset
if err = store.DB.Where("account_id = ?", account.ID).Find(&assets).Error; err != nil {
ErrResponse(w, http.StatusInternalServerError, err)
return
}
// construct response
status := &AccountStatus{}
status.StorageAvailable = getNumConfigValue(CNFStorage, 0)
for _, asset := range assets {
status.StorageUsed += asset.Size
}
status.Disabled = account.Disabled
status.ForwardingAddress = account.Forward
status.Searchable = account.Searchable
status.PushEnabled = account.PushEnabled
2022-07-22 19:28:14 +00:00
WriteResponse(w, status)
2022-03-08 21:31:04 +00:00
}