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:
Summer⛱
2023-11-03 13:46:04 +08:00
committed by GitHub
parent e8212ff05e
commit 90026020a8
2 changed files with 15 additions and 5 deletions

View File

@@ -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) => {

View File

@@ -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');
});
});