feat(storage): add rate limiting, file versioning endpoints, and version tests

Rate Limiting:
- Add @nestjs/throttler with 100 req/min global limit
- Stricter limits for uploads: 20 req/min single, 10 req/min multi

File Versioning (Backend):
- GET /api/v1/files/:id/versions — list version history
- POST /api/v1/files/:id/versions — upload new version with optional comment
- Updates file metadata (size, name, storageKey) on new version
- 7 new tests for versioning service and controller

API Client (Frontend):
- Add FileVersion interface
- Add filesApi.getVersions() and filesApi.uploadVersion()

Total tests: 205 (140 backend + 65 web)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-03-21 21:23:28 +01:00
parent c7b105bc00
commit 9085dddfad
6 changed files with 387 additions and 4 deletions

View file

@ -116,6 +116,19 @@ export interface Share {
createdAt: string;
}
export interface FileVersion {
id: string;
fileId: string;
versionNumber: number;
storagePath: string;
storageKey: string;
size: number;
checksum: string | null;
comment: string | null;
createdBy: string;
createdAt: string;
}
export interface Tag {
id: string;
userId: string;
@ -172,6 +185,20 @@ export const filesApi = {
delete: (id: string) => request<{ success: boolean }>(`/files/${id}`, { method: 'DELETE' }),
toggleFavorite: (id: string) => request<StorageFile>(`/files/${id}/favorite`, { method: 'POST' }),
getVersions: (fileId: string) => request<FileVersion[]>(`/files/${fileId}/versions`),
uploadVersion: async (
fileId: string,
file: File,
comment?: string
): Promise<ApiResponse<FileVersion>> => {
const formData = new FormData();
formData.append('file', file);
if (comment) formData.append('comment', comment);
const result = await api.upload<FileVersion>(`/files/${fileId}/versions`, formData);
return toLegacyResponse(result);
},
};
// Folders API