From ead73db7594d3610df77eb183135b186640d049a Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Mon, 10 Jul 2023 22:15:02 -0700 Subject: [PATCH] displaying storage used by accounts --- doc/api.oa3 | 3 +++ net/server/internal/api_getNodeAccounts.go | 8 +++++++- net/server/internal/models.go | 2 ++ net/server/internal/store/schema.go | 1 + net/web/src/dashboard/accountItem/AccountItem.jsx | 7 ++++++- net/web/src/dashboard/accountItem/AccountItem.styled.js | 5 +++++ net/web/src/dashboard/accountItem/useAccountItem.hook.js | 3 +++ 7 files changed, 27 insertions(+), 2 deletions(-) diff --git a/doc/api.oa3 b/doc/api.oa3 index ebb0ba21..b57f1b96 100644 --- a/doc/api.oa3 +++ b/doc/api.oa3 @@ -3975,6 +3975,9 @@ components: type: boolean seal: type: string + storageUsed: + type: integer + format: int64 Profile: type: object diff --git a/net/server/internal/api_getNodeAccounts.go b/net/server/internal/api_getNodeAccounts.go index b6b18746..012f2fe1 100644 --- a/net/server/internal/api_getNodeAccounts.go +++ b/net/server/internal/api_getNodeAccounts.go @@ -14,13 +14,18 @@ func GetNodeAccounts(w http.ResponseWriter, r *http.Request) { } var accounts []store.Account - if err := store.DB.Preload("AccountDetail").Find(&accounts).Error; err != nil { + if err := store.DB.Preload("Assets").Preload("AccountDetail").Find(&accounts).Error; err != nil { ErrResponse(w, http.StatusInternalServerError, err) return } profiles := []AccountProfile{} for _, account := range accounts { + var size int64 + for _, asset := range account.Assets { + size += asset.Size + } + profiles = append(profiles, AccountProfile{ AccountID: uint32(account.ID), GUID: account.GUID, @@ -30,6 +35,7 @@ func GetNodeAccounts(w http.ResponseWriter, r *http.Request) { Location: account.AccountDetail.Location, ImageSet: account.AccountDetail.Image != "", Disabled: account.Disabled, + StorageUsed: size, }) } diff --git a/net/server/internal/models.go b/net/server/internal/models.go index 0417d9db..5c35d6d2 100644 --- a/net/server/internal/models.go +++ b/net/server/internal/models.go @@ -19,6 +19,8 @@ type AccountProfile struct { Seal string `json:"seal,emitempty"` Disabled bool `json:"disabled"` + + StorageUsed int64 `json:"storageUsed"` } //AccountStatus server settings for account diff --git a/net/server/internal/store/schema.go b/net/server/internal/store/schema.go index b4b9e841..a479b1bb 100644 --- a/net/server/internal/store/schema.go +++ b/net/server/internal/store/schema.go @@ -84,6 +84,7 @@ type Account struct { Forward string AccountDetail AccountDetail Apps []App + Assets []Asset } type AccountDetail struct { diff --git a/net/web/src/dashboard/accountItem/AccountItem.jsx b/net/web/src/dashboard/accountItem/AccountItem.jsx index e0addccd..b3007117 100644 --- a/net/web/src/dashboard/accountItem/AccountItem.jsx +++ b/net/web/src/dashboard/accountItem/AccountItem.jsx @@ -75,7 +75,12 @@ export function AccountItem({ item, remove }) {
-
{ state.handle }
+
+ { state.handle } + { state?.storage > 0 && ( + { state.storage } { state.storageUnit } + )} +
{ state.guid }
diff --git a/net/web/src/dashboard/accountItem/AccountItem.styled.js b/net/web/src/dashboard/accountItem/AccountItem.styled.js index de4976a9..fd6911f4 100644 --- a/net/web/src/dashboard/accountItem/AccountItem.styled.js +++ b/net/web/src/dashboard/accountItem/AccountItem.styled.js @@ -51,6 +51,11 @@ export const AccountItemWrapper = styled.div` overflow: hidden; } + .storage { + color: #555555; + padding-left: 8px; + } + .guid { font-size: 0.8em; font-weight: bold; diff --git a/net/web/src/dashboard/accountItem/useAccountItem.hook.js b/net/web/src/dashboard/accountItem/useAccountItem.hook.js index 5bc93327..b4679102 100644 --- a/net/web/src/dashboard/accountItem/useAccountItem.hook.js +++ b/net/web/src/dashboard/accountItem/useAccountItem.hook.js @@ -22,6 +22,7 @@ export function useAccountItem(item, remove) { } useEffect(() => { + updateState({ disabled: item?.disabled, activeClass: item?.disabled ? 'inactive' : 'active', @@ -29,6 +30,8 @@ export function useAccountItem(item, remove) { name: item?.name, guid: item?.guid, handle: item?.handle, + storage: Math.floor(item?.storageUsed > 1073741824 ? item?.storageUsed / 1073741824 : item?.storageUsed / 1048576), + storageUnit: item?.storageUsed > 1073741824 ? "GB" : "MB", imageUrl: item?.imageSet ? getAccountImageUrl(app.state.adminToken, item?.accountId) : null, }); }, [app.state.adminToken, item]);