All checks were successful
Build and push image / release-image (push) Successful in 1m32s
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
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<string>('MINIO_ENDPOINT'),
|
|
credentials: {
|
|
accessKeyId: this.configService.get<string>('MINIO_ACCESSKEY'),
|
|
secretAccessKey: this.configService.get<string>('MINIO_SECRETKEY'),
|
|
},
|
|
forcePathStyle: true,
|
|
} as S3ClientConfig);
|
|
}
|
|
|
|
getHealthz(): string {
|
|
return 'OK';
|
|
}
|
|
|
|
async getObject(
|
|
getObjectConfig: GetObjectCommandInput,
|
|
): Promise<GetObjectCommandOutput | null> {
|
|
const command = new GetObjectCommand(getObjectConfig);
|
|
try {
|
|
return await this.s3Client.send(command);
|
|
} catch (err: unknown) {
|
|
if (err instanceof NoSuchKey) return null;
|
|
throw err;
|
|
}
|
|
}
|
|
}
|