Feat: repo api done

This commit is contained in:
2025-07-10 15:04:24 +08:00
parent 6374a3815e
commit 0a87670469
7 changed files with 1382 additions and 14 deletions

View File

@@ -1,8 +1,41 @@
import { Injectable } from '@nestjs/common';
import { Readable } from 'stream';
import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import {
S3Client,
S3ClientConfig,
GetObjectCommand,
GetObjectCommandInput,
} from '@aws-sdk/client-s3';
@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
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<Readable> {
const command = new GetObjectCommand(getObjectConfig);
const res = await this.s3Client.send(command);
if (!res.Body)
throw new HttpException(
's3 get object failed',
HttpStatus.INTERNAL_SERVER_ERROR,
);
return res.Body as Readable;
}
}