fix(membership): replace hardcoded 1GB storage with API-driven quota
This commit is contained in:
parent
e2511855fe
commit
3e8c4dfa63
@ -11,11 +11,14 @@ class ProfileViewModel: ObservableObject {
|
||||
@Published var itemCount = 0
|
||||
@Published var cardCount = 0
|
||||
@Published var usedBytes = 0
|
||||
@Published var totalBytes = 1073741824
|
||||
@Published var totalBytes = 0 // M-MEMBER-01-CLOSE-01C: 来自 /membership/me,不再硬编码 1GB
|
||||
@Published var storageUnavailable = false
|
||||
@Published var isLoading = false
|
||||
@Published var errorMessage: String?
|
||||
|
||||
var formattedStorage: String {
|
||||
if storageUnavailable { return "暂时无法获取" }
|
||||
if totalBytes == 0 { return "加载中…" }
|
||||
if usedBytes < 1024 * 1024 { return "\(usedBytes / 1024) KB / \(totalBytes / 1024 / 1024 / 1024) GB" }
|
||||
return String(format: "%.0f MB / %d GB", Double(usedBytes) / 1024 / 1024, totalBytes / 1024 / 1024 / 1024)
|
||||
}
|
||||
@ -23,6 +26,7 @@ class ProfileViewModel: ObservableObject {
|
||||
func loadAll() async {
|
||||
isLoading = true; errorMessage = nil
|
||||
await loadProfile()
|
||||
await loadStorageQuota()
|
||||
isLoading = false
|
||||
Task { await loadActivitySummary() }
|
||||
Task { await loadStats() }
|
||||
@ -41,10 +45,24 @@ class ProfileViewModel: ObservableObject {
|
||||
if let assets = await a { kbCount = assets.knowledgeBaseCount; itemCount = assets.knowledgeItemCount; cardCount = assets.reviewCardCount }
|
||||
if let storage = await s { usedBytes = storage.usedBytes; totalBytes = storage.totalBytes }
|
||||
}
|
||||
|
||||
// M-MEMBER-01-CLOSE-01C: 从 /membership/me 获取真实存储配额
|
||||
private func loadStorageQuota() async {
|
||||
do {
|
||||
let membership = try await MembershipService.shared.myMembership()
|
||||
if let storage = membership.entitlements?.maxStorageBytes, storage > 0 {
|
||||
totalBytes = storage
|
||||
storageUnavailable = false
|
||||
} else {
|
||||
storageUnavailable = true
|
||||
}
|
||||
} catch {
|
||||
storageUnavailable = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Raw API models
|
||||
|
||||
struct AssetsResponse: Codable {
|
||||
let knowledgeBaseCount: Int
|
||||
let knowledgeItemCount: Int
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user