feat: H0-10 存储空间统计 + 学习资产计数
Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 19s

- GET /users/me/storage(totalBytes/usedBytes/fileCount)
- GET /users/me/assets-summary(kbCount/itemCount/cardCount)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
wangdl 2026-05-29 19:29:22 +08:00
parent d208fd7876
commit 5fe31a8805
2 changed files with 37 additions and 0 deletions

View File

@ -77,4 +77,18 @@ export class UsersController {
async removeDevice(@CurrentUser() user: UserPayload, @Param('deviceId') deviceId: string) {
return this.usersService.removeDevice(String(user.id), deviceId);
}
// ── Storage & Assets ──
@Get('me/storage')
@ApiOperation({ summary: '存储空间统计' })
async getStorage(@CurrentUser() user: UserPayload) {
return this.usersService.getStorage(String(user.id));
}
@Get('me/assets-summary')
@ApiOperation({ summary: '学习资产摘要' })
async getAssetsSummary(@CurrentUser() user: UserPayload) {
return this.usersService.getAssetsSummary(String(user.id));
}
}

View File

@ -68,4 +68,27 @@ export class UsersService {
});
return { success: true };
}
// ── Storage ──
async getStorage(userId: string) {
const files = await this.prisma.uploadedFile.findMany({
where: { userId },
select: { sizeBytes: true, mimeType: true },
});
const usedBytes = files.reduce((sum, f) => sum + f.sizeBytes, 0);
const totalBytes = 1024 * 1024 * 1024; // 1GB hardcoded for now
return { totalBytes, usedBytes, fileCount: files.length };
}
// ── Assets Summary ──
async getAssetsSummary(userId: string) {
const [kbCount, itemCount, cardCount] = await Promise.all([
this.prisma.knowledgeBase.count({ where: { userId, deletedAt: null } }),
this.prisma.knowledgeItem.count({ where: { userId, deletedAt: null } }),
this.prisma.reviewCard.count({ where: { userId } }),
]);
return { knowledgeBaseCount: kbCount, knowledgeItemCount: itemCount, reviewCardCount: cardCount };
}
}