mirror of
https://github.com/aljazceru/ditto.git
synced 2025-12-29 03:04:25 +01:00
Trends: support limit param
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
import { type AppController } from '@/app.ts';
|
||||
import { Conf } from '@/config.ts';
|
||||
import { z } from '@/deps.ts';
|
||||
import { trends } from '@/trends.ts';
|
||||
import { Time } from '@/utils.ts';
|
||||
|
||||
const limitSchema = z.coerce.number().catch(10).transform((value) => Math.min(Math.max(value, 0), 20));
|
||||
|
||||
const trendingTagsController: AppController = (c) => {
|
||||
const limit = limitSchema.parse(c.req.query('limit'));
|
||||
if (limit < 1) return c.json([]);
|
||||
|
||||
const now = new Date();
|
||||
const yesterday = new Date(now.getTime() - Time.days(1));
|
||||
|
||||
const tags = trends.getTrendingTags(yesterday, now);
|
||||
const tags = trends.getTrendingTags(yesterday, now, limit);
|
||||
|
||||
return c.json(tags.map(({ name, accounts, uses }) => ({
|
||||
name,
|
||||
|
||||
Reference in New Issue
Block a user