Files
archrepo/src/app.service.ts
Yi-Ting Shih 4e3ac71c78
All checks were successful
Build and push image / release-image (push) Successful in 1m32s
Chore: lint
2025-07-10 18:02:49 +08:00

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;
}
}
}