|
| 1 | +import { Injectable } from '@nestjs/common'; |
| 2 | +import { ConfigService as NestConfigService } from '@nestjs/config'; |
| 3 | +import { EnvironmentVariables } from './env.validation'; |
| 4 | + |
| 5 | +@Injectable() |
| 6 | +export class AppConfigService { |
| 7 | + constructor(private configService: NestConfigService<EnvironmentVariables>) {} |
| 8 | + |
| 9 | + /** |
| 10 | + * Get server port from environment |
| 11 | + */ |
| 12 | + get port(): number { |
| 13 | + return this.configService.get('PORT'); |
| 14 | + } |
| 15 | + |
| 16 | + /** |
| 17 | + * Get JWT secret key for token generation |
| 18 | + */ |
| 19 | + get jwtSecret(): string { |
| 20 | + return this.configService.get('JWT_SECRET'); |
| 21 | + } |
| 22 | + |
| 23 | + /** |
| 24 | + * Get JWT refresh token secret |
| 25 | + */ |
| 26 | + get jwtRefresh(): string { |
| 27 | + return this.configService.get('JWT_REFRESH'); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Get password hashing salt rounds |
| 32 | + */ |
| 33 | + get saltRounds(): number { |
| 34 | + return this.configService.get('SALT_ROUNDS'); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Get OpenAI API base URI |
| 39 | + */ |
| 40 | + get openaiBaseUri(): string { |
| 41 | + return this.configService.get('OPENAI_BASE_URI'); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Get S3/Cloudflare R2 configuration object |
| 46 | + */ |
| 47 | + get s3Config() { |
| 48 | + return { |
| 49 | + accessKeyId: this.configService.get('S3_ACCESS_KEY_ID'), |
| 50 | + secretAccessKey: this.configService.get('S3_SECRET_ACCESS_KEY'), |
| 51 | + region: this.configService.get('S3_REGION'), |
| 52 | + bucketName: this.configService.get('S3_BUCKET_NAME'), |
| 53 | + endpoint: this.configService.get('S3_ENDPOINT'), |
| 54 | + accountId: this.configService.get('S3_ACCOUNT_ID'), |
| 55 | + publicUrl: this.configService.get('S3_PUBLIC_URL'), |
| 56 | + }; |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Check if S3 storage is properly configured |
| 61 | + */ |
| 62 | + get hasS3Configured(): boolean { |
| 63 | + const config = this.s3Config; |
| 64 | + return !!( |
| 65 | + config.accessKeyId && |
| 66 | + config.secretAccessKey && |
| 67 | + config.region && |
| 68 | + (config.endpoint || config.accountId) |
| 69 | + ); |
| 70 | + } |
| 71 | +} |
0 commit comments