Commit dade795c authored by nanahira's avatar nanahira

add middleware info

parent 6b24584a
Pipeline #5419 passed with stages
in 2 minutes and 57 seconds
import { Body, Controller, Get, Post, ValidationPipe } from '@nestjs/common';
import { AppService } from './app.service';
import { ApiBody, ApiCreatedResponse, ApiOperation } from '@nestjs/swagger';
import {
ApiBody,
ApiCreatedResponse,
ApiOkResponse,
ApiOperation,
} from '@nestjs/swagger';
import { PostUrlDto } from './dto/PostUrl.dto';
import { StringReturnMessageDto } from './dto/ReturnMessage.dto';
import {
MiddlewareInfoReturnMessageDto,
StringReturnMessageDto,
} from './dto/ReturnMessage.dto';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get('jsd')
@ApiOperation({ summary: 'JSDelivr', description: '需要配置 JSD_URL' })
@ApiOkResponse({ type: MiddlewareInfoReturnMessageDto })
jsdInfo() {
return this.appService.jsdInfo();
}
@Post('jsd')
@ApiOperation({ summary: 'JSDelivr', description: '需要配置 JSD_URL' })
@ApiBody({ type: PostUrlDto })
......
......@@ -11,13 +11,16 @@ import {
import FormData from 'form-data';
import { PostUrlDto } from './dto/PostUrl.dto';
import hasha from 'hasha';
import { MiddlewareInfoDto } from './dto/MiddlewareInfo.dto';
@Injectable()
export class AppService extends ConsoleLogger {
private jsdUrl: string;
private jsdIdentifier: string;
constructor(config: ConfigService, private http: HttpService) {
super('app');
this.jsdUrl = config.get('JSD_URL');
this.jsdIdentifier = config.get('JSD_IDENTIFIER') || `jsd-${this.jsdUrl}`;
}
private async getStreamFromUrl(url: string) {
......@@ -34,6 +37,16 @@ export class AppService extends ConsoleLogger {
}
}
jsdInfo() {
if (!this.jsdUrl) {
throw new BlankReturnMessageDto(404, 'JSDelivr is not configured.');
}
const info = new MiddlewareInfoDto();
info.identifier = this.jsdIdentifier;
info.maxSize = 50 * 1024 * 1024;
return new ReturnMessageDto(200, 'success', info);
}
async jsd(urlDto: PostUrlDto) {
if (!this.jsdUrl) {
throw new BlankReturnMessageDto(404, 'JSDelivr is not configured.');
......
import { ApiProperty } from '@nestjs/swagger';
export class MiddlewareInfoDto {
@ApiProperty({ description: '标识符' })
identifier: string;
@ApiProperty({ description: '最大文件大小' })
maxSize?: number;
}
import { ApiProperty } from '@nestjs/swagger';
import { HttpException } from '@nestjs/common';
import { MiddlewareInfoDto } from './MiddlewareInfo.dto';
export interface BlankReturnMessage {
statusCode: number;
......@@ -44,3 +45,8 @@ export class StringReturnMessageDto extends BlankReturnMessageDto {
@ApiProperty({ description: '返回内容' })
data: string;
}
export class MiddlewareInfoReturnMessageDto extends BlankReturnMessageDto {
@ApiProperty({ description: '返回内容' })
data: MiddlewareInfoDto;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment