From 18ef334f0db894be0c9beab91eb1faba05bab6a7 Mon Sep 17 00:00:00 2001 From: wangdl Date: Fri, 26 Jun 2026 20:59:34 +0800 Subject: [PATCH] fix(quota): replace hardcoded 1GB storage with EffectiveQuota lookup - UsersService.getStorage() now reads storage_bytes from EffectiveQuota - Falls back to 1GB only when quota service is unavailable - iOS already reads from /membership/me (CLOSE-01C) Co-Authored-By: Claude --- src/modules/users/users.service.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/modules/users/users.service.ts b/src/modules/users/users.service.ts index 907dc82..99f936a 100644 --- a/src/modules/users/users.service.ts +++ b/src/modules/users/users.service.ts @@ -2,6 +2,7 @@ import { Injectable, BadRequestException, NotFoundException, Inject, Optional } import { UsersRepository } from './users.repository'; import { PrismaService } from '../../infrastructure/database/prisma.service'; import { EffectiveMembershipService } from '../membership/effective-membership.service'; +import { EffectiveQuotaService } from '../membership/effective-quota.service'; const DELETION_COOLING_DAYS = 7; @@ -12,6 +13,7 @@ export class UsersService { private readonly prisma: PrismaService, // M-MEMBER-01-04: 可选注入——避免循环依赖。未注入时回退旧逻辑。 @Optional() @Inject(EffectiveMembershipService) private readonly membershipService?: EffectiveMembershipService, + @Optional() @Inject(EffectiveQuotaService) private readonly quotaService?: EffectiveQuotaService, ) {} async getProfile(userId: string) { return this.usersRepository.findProfileByUserId(userId); } @@ -90,7 +92,15 @@ export class UsersService { select: { sizeBytes: true, mimeType: true }, }); const usedBytes = files.reduce((sum, f) => sum + Number(f.sizeBytes), 0); - const totalBytes = 1024 * 1024 * 1024; // 1GB hardcoded for now + // M-MEMBER-01-CLOSE-01E: 从 EffectiveQuota 读取真实存储配额,不再硬编码 1GB + let totalBytes = 1073741824; // fallback(quota 不可用时) + if (this.quotaService) { + try { + const q = await this.quotaService.computeEffectiveQuota(userId); + const storageLimit = q.limits.find(l => l.quotaType === 'storage_bytes'); + if (storageLimit && !storageLimit.isUnlimited) totalBytes = storageLimit.limit; + } catch { /* keep fallback */ } + } return { totalBytes, usedBytes, fileCount: files.length }; }