mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 11:39:17 +00:00
37 lines
790 B
Go
37 lines
790 B
Go
|
package databag
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"databag/internal/store"
|
||
|
)
|
||
|
|
||
|
func GetAccountStatus(w http.ResponseWriter, r *http.Request) {
|
||
|
|
||
|
account, err := AccountLogin(r)
|
||
|
if err != nil {
|
||
|
ErrResponse(w, http.StatusUnauthorized, 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(CONFIG_STORAGE, 0);
|
||
|
for _, asset := range assets {
|
||
|
status.StorageUsed += asset.Size
|
||
|
}
|
||
|
status.Disabled = account.Disabled
|
||
|
status.ForwardingAddress = account.Forward
|
||
|
status.Searchable = account.Searchable
|
||
|
|
||
|
WriteResponse(w, status)
|
||
|
}
|
||
|
|
||
|
|
||
|
|