databag/net/server/internal/api_getAccountStatus.go
2022-07-22 12:28:14 -07:00

34 lines
750 B
Go

package databag
import (
"databag/internal/store"
"net/http"
)
func GetAccountStatus(w http.ResponseWriter, r *http.Request) {
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
WriteResponse(w, status)
}