import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { S3Client, S3ClientConfig, GetObjectCommand, GetObjectCommandInput, GetObjectCommandOutput, NoSuchKey, } from '@aws-sdk/client-s3'; @Injectable() export class AppService { private readonly s3Client: S3Client; constructor(private readonly configService: ConfigService) { this.s3Client = new S3Client({ region: 'us-west-1', endpoint: this.configService.get('MINIO_ENDPOINT'), credentials: { accessKeyId: this.configService.get('MINIO_ACCESSKEY'), secretAccessKey: this.configService.get('MINIO_SECRETKEY'), }, forcePathStyle: true, } as S3ClientConfig); } getHealthz(): string { return 'OK'; } async getObject( getObjectConfig: GetObjectCommandInput, ): Promise { const command = new GetObjectCommand(getObjectConfig); try { return await this.s3Client.send(command); } catch (err: unknown) { if (err instanceof NoSuchKey) return null; throw err; } } }