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-12-04 00:57:22 +00:00
|
|
|
session, code, err := GetSessionDetail(r)
|
2022-07-22 19:28:14 +00:00
|
|
|
if err != nil {
|
|
|
|
ErrResponse(w, code, err)
|
|
|
|
return
|
|
|
|
}
|
2022-11-14 07:27:15 +00:00
|
|
|
account := session.Account
|
2022-07-22 19:28:14 +00:00
|
|
|
|
|
|
|
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
|
2022-12-04 00:57:22 +00:00
|
|
|
seal := &Seal{}
|
2022-12-07 06:52:53 +00:00
|
|
|
seal.PasswordSalt = account.AccountDetail.SealSalt
|
|
|
|
seal.PrivateKeyIV = account.AccountDetail.SealIV
|
2022-12-04 00:57:22 +00:00
|
|
|
seal.PrivateKeyEncrypted = account.AccountDetail.SealPrivate
|
|
|
|
seal.PublicKey = account.AccountDetail.SealPublic
|
2022-07-22 19:28:14 +00:00
|
|
|
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
|
2022-12-19 22:42:08 +00:00
|
|
|
status.Sealable = true
|
2022-11-14 07:27:15 +00:00
|
|
|
status.PushEnabled = session.PushEnabled
|
2022-12-04 00:57:22 +00:00
|
|
|
status.Seal = seal
|
2022-07-22 19:28:14 +00:00
|
|
|
WriteResponse(w, status)
|
2022-03-08 21:31:04 +00:00
|
|
|
}
|