File size: 2,080 Bytes
95d29a5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
import {
Controller,
DefaultValuePipe,
Get,
Logger,
Param,
ParseIntPipe,
Query,
Request,
Response,
} from '@nestjs/common';
import { FeedsService } from './feeds.service';
import { Response as Res, Request as Req } from 'express';
@Controller('feeds')
export class FeedsController {
private readonly logger = new Logger(this.constructor.name);
constructor(private readonly feedsService: FeedsService) {}
@Get('/')
async getFeedList() {
return this.feedsService.getFeedList();
}
@Get('/all.(json|rss|atom)')
async getFeeds(
@Request() req: Req,
@Response() res: Res,
@Query('limit', new DefaultValuePipe(30), ParseIntPipe) limit: number = 30,
@Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number = 1,
@Query('mode') mode: string,
@Query('title_include') title_include: string,
@Query('title_exclude') title_exclude: string,
) {
const path = req.path;
const type = path.split('.').pop() || '';
const { content, mimeType } = await this.feedsService.handleGenerateFeed({
type,
limit,
page,
mode,
title_include,
title_exclude,
});
res.setHeader('Content-Type', mimeType);
res.send(content);
}
@Get('/:feed')
async getFeed(
@Response() res: Res,
@Param('feed') feed: string,
@Query('limit', new DefaultValuePipe(10), ParseIntPipe) limit: number = 10,
@Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number = 1,
@Query('mode') mode: string,
@Query('title_include') title_include: string,
@Query('title_exclude') title_exclude: string,
@Query('update') update: boolean = false,
) {
const [id, type] = feed.split('.');
this.logger.log('getFeed: ', id);
if (update) {
this.feedsService.updateFeed(id);
}
const { content, mimeType } = await this.feedsService.handleGenerateFeed({
id,
type,
limit,
page,
mode,
title_include,
title_exclude,
});
res.setHeader('Content-Type', mimeType);
res.send(content);
}
}
|