mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-10 15:21:59 +08:00
fix(parameter): adjust to filter before limit. (#13682)
* fix(parameter): adjust to filter before limit. * fix(parameter): add test. * fix
This commit is contained in:
@@ -149,11 +149,6 @@ module.exports = async (ctx, next) => {
|
||||
ctx.state.data.item = await Promise.all(ctx.state.data.item.map(handleItem));
|
||||
|
||||
if (ctx.query) {
|
||||
// limit
|
||||
if (ctx.query.limit) {
|
||||
ctx.state.data.item = ctx.state.data.item.slice(0, parseInt(ctx.query.limit));
|
||||
}
|
||||
|
||||
// filter
|
||||
const engine = config.feature.filter_regex_engine;
|
||||
const makeRegex = (string) => {
|
||||
@@ -251,6 +246,11 @@ module.exports = async (ctx, next) => {
|
||||
});
|
||||
}
|
||||
|
||||
// limit
|
||||
if (ctx.query.limit) {
|
||||
ctx.state.data.item = ctx.state.data.item.slice(0, parseInt(ctx.query.limit));
|
||||
}
|
||||
|
||||
// telegram instant view
|
||||
if (ctx.query.tgiv) {
|
||||
ctx.state.data.item.map((item) => {
|
||||
|
||||
@@ -403,3 +403,13 @@ describe('opencc', () => {
|
||||
expect(parsed.items[0].content).toBe('宇宙无敌');
|
||||
});
|
||||
});
|
||||
|
||||
describe('multi parameter', () => {
|
||||
it(`filter before limit`, async () => {
|
||||
const response = await request.get('/test/filter-limit?filterout_title=2&limit=2');
|
||||
const parsed = await parser.parseString(response.text);
|
||||
expect(parsed.items.length).toBe(2);
|
||||
expect(parsed.items[0].title).toBe('Title1');
|
||||
expect(parsed.items[1].title).toBe('Title3');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user