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 <noreply@anthropic.com>
This commit is contained in:
parent
ac7a2201ab
commit
18ef334f0d
@ -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 };
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user