Skip to content

Commit

Permalink
fix dashboard api
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Sep 10, 2024
1 parent 104348b commit 9c47da8
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions app/api/endpoints/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from app import schemas
from app.chain.dashboard import DashboardChain
from app.chain.storage import StorageChain
from app.core.security import verify_token, verify_apitoken
from app.db import get_db
from app.db.models.transferhistory import TransferHistory
Expand Down Expand Up @@ -48,11 +49,19 @@ def storage(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
"""
查询本地存储空间信息
"""
library_dirs = DirectoryHelper().get_local_library_dirs()
total_storage, free_storage = SystemUtils.space_usage([Path(d.library_path) for d in library_dirs])
total, available = 0, 0
dirs = DirectoryHelper().get_dirs()
if not dirs:
return schemas.Storage(total_storage=total, used_storage=total - available)
storages = set([d.library_storage for d in dirs if d.library_storage])
for _storage in storages:
_usage = StorageChain().storage_usage(_storage)
if _usage:
total += _usage.total
available += _usage.available
return schemas.Storage(
total_storage=total_storage,
used_storage=total_storage - free_storage
total_storage=total,
used_storage=total - available
)


Expand Down

0 comments on commit 9c47da8

Please sign in to comment.