feat(backend): implement phases 0-6 (auth, kc, wahl, files, chat, sync)
Full NestJS backend for the KC-App platform: - auth: Authentik OIDC resource-server strategy + guest invite-code JWT login, plus TokenVerificationService for the WS handshake path - kc: Leitungsteam-only KC (event) creation/listing - wahl: Wahl/Workshop admin, Force-Zuteilung overrides, ZuteilungService (port of the WP plugin's kc_run_zuteilung), CSV export - files: LT-only upload with visibility tiers; list/download filtered by caller tier; StorageProvider abstraction (WebDAV/Nextcloud default, S3) - chat: Gemeinde group / DM / LT-wide / broadcast channels; REST + raw ws gateway sharing ChatService access rules - sync: append-only SyncLogEntry replication log + local<->cloud push/pull scheduler, shared-secret guarded - common: Role enum, @Roles decorator, KC-scoped RolesGuard (LT global) - serves client/web/ interim static web client under / (API under /api) Typecheck, nest build and boot test pass; needs real Postgres/Authentik/ Nextcloud to run end to end. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { randomUUID } from 'crypto';
|
||||
import {
|
||||
DeleteObjectCommand,
|
||||
GetObjectCommand,
|
||||
PutObjectCommand,
|
||||
S3Client,
|
||||
} from '@aws-sdk/client-s3';
|
||||
import { StorageProvider } from './storage-provider';
|
||||
|
||||
/// S3-compatible object storage (AWS S3, MinIO, etc.).
|
||||
@Injectable()
|
||||
export class S3StorageProvider implements StorageProvider {
|
||||
private readonly client: S3Client;
|
||||
private readonly bucket: string;
|
||||
|
||||
constructor(config: ConfigService) {
|
||||
this.bucket = config.getOrThrow<string>('S3_BUCKET');
|
||||
this.client = new S3Client({
|
||||
region: config.get<string>('S3_REGION') ?? 'auto',
|
||||
endpoint: config.get<string>('S3_ENDPOINT'),
|
||||
forcePathStyle: config.get<string>('S3_FORCE_PATH_STYLE') === 'true',
|
||||
credentials: {
|
||||
accessKeyId: config.getOrThrow<string>('S3_ACCESS_KEY_ID'),
|
||||
secretAccessKey: config.getOrThrow<string>('S3_SECRET_ACCESS_KEY'),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async upload(kcId: string, filename: string, data: Buffer): Promise<string> {
|
||||
const storageKey = `${kcId}/${randomUUID()}-${filename}`;
|
||||
await this.client.send(
|
||||
new PutObjectCommand({ Bucket: this.bucket, Key: storageKey, Body: data }),
|
||||
);
|
||||
return storageKey;
|
||||
}
|
||||
|
||||
async download(storageKey: string): Promise<Buffer> {
|
||||
const result = await this.client.send(
|
||||
new GetObjectCommand({ Bucket: this.bucket, Key: storageKey }),
|
||||
);
|
||||
const chunks: Uint8Array[] = [];
|
||||
for await (const chunk of result.Body as AsyncIterable<Uint8Array>) {
|
||||
chunks.push(chunk);
|
||||
}
|
||||
return Buffer.concat(chunks);
|
||||
}
|
||||
|
||||
async delete(storageKey: string): Promise<void> {
|
||||
await this.client.send(new DeleteObjectCommand({ Bucket: this.bucket, Key: storageKey }));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user