From 3e8c4dfa63eb4ad3f86e2ecc812b0a96f487a4e9 Mon Sep 17 00:00:00 2001 From: wangdl Date: Fri, 26 Jun 2026 20:28:09 +0800 Subject: [PATCH] fix(membership): replace hardcoded 1GB storage with API-driven quota --- .../Features/Profile/ProfileViewModel.swift | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/AIStudyApp/AIStudyApp/Features/Profile/ProfileViewModel.swift b/AIStudyApp/AIStudyApp/Features/Profile/ProfileViewModel.swift index 80fed17..2d63a62 100644 --- a/AIStudyApp/AIStudyApp/Features/Profile/ProfileViewModel.swift +++ b/AIStudyApp/AIStudyApp/Features/Profile/ProfileViewModel.swift @@ -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