Feat: add package list
All checks were successful
Build and push image / release-image (push) Successful in 3m34s
All checks were successful
Build and push image / release-image (push) Successful in 3m34s
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "archrepo",
|
"name": "archrepo",
|
||||||
"version": "0.0.1",
|
"version": "2.0.2",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "",
|
"author": "",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
Header,
|
Header,
|
||||||
Res,
|
Res,
|
||||||
Param,
|
Param,
|
||||||
|
Query,
|
||||||
Headers,
|
Headers,
|
||||||
HttpException,
|
HttpException,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
@@ -14,7 +15,10 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { ApiOkResponse, ApiNotFoundResponse } from '@nestjs/swagger';
|
import { ApiOkResponse, ApiNotFoundResponse } from '@nestjs/swagger';
|
||||||
import { GetObjectCommandInput } from '@aws-sdk/client-s3';
|
import {
|
||||||
|
GetObjectCommandInput,
|
||||||
|
ListObjectsV2CommandInput,
|
||||||
|
} from '@aws-sdk/client-s3';
|
||||||
|
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
|
|
||||||
@@ -33,9 +37,9 @@ export class AppController {
|
|||||||
|
|
||||||
@ApiOkResponse()
|
@ApiOkResponse()
|
||||||
@ApiNotFoundResponse()
|
@ApiNotFoundResponse()
|
||||||
@Get(`:repo/os/:arch/:pkg`)
|
@Get(':repo/os/:arch/:pkg')
|
||||||
@Header('Accept-Ranges', 'bytes')
|
@Header('Accept-Ranges', 'bytes')
|
||||||
async getRepo(
|
async getPackage(
|
||||||
@Headers('Range') range: string,
|
@Headers('Range') range: string,
|
||||||
@Res({ passthrough: true }) res: Response,
|
@Res({ passthrough: true }) res: Response,
|
||||||
@Param('repo') repo: string,
|
@Param('repo') repo: string,
|
||||||
@@ -66,4 +70,38 @@ export class AppController {
|
|||||||
}
|
}
|
||||||
return new StreamableFile(output.Body as Readable);
|
return new StreamableFile(output.Body as Readable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOkResponse()
|
||||||
|
@ApiNotFoundResponse()
|
||||||
|
@Get(':repo/os/:arch')
|
||||||
|
async getPackageList(
|
||||||
|
@Res({ passthrough: true }) res: Response,
|
||||||
|
@Param('repo') repo: string,
|
||||||
|
@Param('arch') arch: string,
|
||||||
|
@Query('format') format: string,
|
||||||
|
): Promise<string> {
|
||||||
|
if (repo !== this.configService.get<string>('REPO_NAME'))
|
||||||
|
throw new HttpException(`Repo '${repo}' not exist`, HttpStatus.NOT_FOUND)
|
||||||
|
if (arch !== this.configService.get<string>('ARCH_NAME'))
|
||||||
|
throw new HttpException(
|
||||||
|
`Architecture '${arch}' not exist`,
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
);
|
||||||
|
|
||||||
|
const output = await this.appService.getObjectList({
|
||||||
|
Bucket: this.configService.get<string>('MINIO_BUCKET')
|
||||||
|
} as ListObjectsV2CommandInput);
|
||||||
|
if (!output) {
|
||||||
|
console.log('Cannot list files');
|
||||||
|
throw new HttpException(`Cannot list files`, HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (format === 'json')
|
||||||
|
return JSON.stringify(output.Contents?.reduce((acc, cur) => {
|
||||||
|
acc.push(cur.Key ?? '');
|
||||||
|
return acc;
|
||||||
|
}, Array<string>()), null, 2);
|
||||||
|
return output.Contents?.reduce(
|
||||||
|
(acc, cur) => `${acc}\n${cur.Key ?? ''}`, '') ?? '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ import {
|
|||||||
GetObjectCommand,
|
GetObjectCommand,
|
||||||
GetObjectCommandInput,
|
GetObjectCommandInput,
|
||||||
GetObjectCommandOutput,
|
GetObjectCommandOutput,
|
||||||
|
ListObjectsV2Command,
|
||||||
|
ListObjectsV2CommandInput,
|
||||||
|
ListObjectsV2CommandOutput,
|
||||||
NoSuchKey,
|
NoSuchKey,
|
||||||
} from '@aws-sdk/client-s3';
|
} from '@aws-sdk/client-s3';
|
||||||
|
|
||||||
@@ -30,9 +33,9 @@ export class AppService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getObject(
|
async getObject(
|
||||||
getObjectConfig: GetObjectCommandInput,
|
config: GetObjectCommandInput,
|
||||||
): Promise<GetObjectCommandOutput | null> {
|
): Promise<GetObjectCommandOutput | null> {
|
||||||
const command = new GetObjectCommand(getObjectConfig);
|
const command = new GetObjectCommand(config);
|
||||||
try {
|
try {
|
||||||
return await this.s3Client.send(command);
|
return await this.s3Client.send(command);
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
@@ -40,4 +43,17 @@ export class AppService {
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getObjectList(
|
||||||
|
config: ListObjectsV2CommandInput,
|
||||||
|
): Promise<ListObjectsV2CommandOutput | null> {
|
||||||
|
const command = new ListObjectsV2Command(config);
|
||||||
|
try {
|
||||||
|
return await this.s3Client.send(command);
|
||||||
|
} catch (err: unknown) {
|
||||||
|
if (err instanceof Error)
|
||||||
|
return null;
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user