fix(quota): replace hardcoded 1GB storage with EffectiveQuota lookup
All checks were successful
Deploy API Server / build-and-unit (push) Successful in 39s
Deploy API Server / current-integration (push) Successful in 33s
Deploy API Server / backward-compat (push) Successful in 0s
Deploy API Server / deploy (push) Successful in 1m5s

- 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 <noreply@anthropic.com>
This commit is contained in:
wangdl 2026-06-26 20:59:34 +08:00
parent ac7a2201ab
commit 18ef334f0d

View File

@ -2,6 +2,7 @@ import { Injectable, BadRequestException, NotFoundException, Inject, Optional }
import { UsersRepository } from './users.repository'; import { UsersRepository } from './users.repository';
import { PrismaService } from '../../infrastructure/database/prisma.service'; import { PrismaService } from '../../infrastructure/database/prisma.service';
import { EffectiveMembershipService } from '../membership/effective-membership.service'; import { EffectiveMembershipService } from '../membership/effective-membership.service';
import { EffectiveQuotaService } from '../membership/effective-quota.service';
const DELETION_COOLING_DAYS = 7; const DELETION_COOLING_DAYS = 7;
@ -12,6 +13,7 @@ export class UsersService {
private readonly prisma: PrismaService, private readonly prisma: PrismaService,
// M-MEMBER-01-04: 可选注入——避免循环依赖。未注入时回退旧逻辑。 // M-MEMBER-01-04: 可选注入——避免循环依赖。未注入时回退旧逻辑。
@Optional() @Inject(EffectiveMembershipService) private readonly membershipService?: EffectiveMembershipService, @Optional() @Inject(EffectiveMembershipService) private readonly membershipService?: EffectiveMembershipService,
@Optional() @Inject(EffectiveQuotaService) private readonly quotaService?: EffectiveQuotaService,
) {} ) {}
async getProfile(userId: string) { return this.usersRepository.findProfileByUserId(userId); } async getProfile(userId: string) { return this.usersRepository.findProfileByUserId(userId); }
@ -90,7 +92,15 @@ export class UsersService {
select: { sizeBytes: true, mimeType: true }, select: { sizeBytes: true, mimeType: true },
}); });
const usedBytes = files.reduce((sum, f) => sum + Number(f.sizeBytes), 0); 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; // fallbackquota 不可用时)
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 }; return { totalBytes, usedBytes, fileCount: files.length };
} }