mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
feat: filter global and local feed by language
add a 'language' field in publicQuerySchema
This commit is contained in:
parent
d72ec843cf
commit
dac11a9055
1 changed files with 16 additions and 1 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import ISO6391 from 'iso-639-1';
|
||||
import { NostrFilter } from '@nostrify/nostrify';
|
||||
import { z } from 'zod';
|
||||
|
||||
|
|
@ -20,11 +21,21 @@ const homeTimelineController: AppController = async (c) => {
|
|||
const publicQuerySchema = z.object({
|
||||
local: booleanParamSchema.catch(false),
|
||||
instance: z.string().optional().catch(undefined),
|
||||
language: z.string().max(2).transform((val, ctx) => {
|
||||
if (!ISO6391.validate(val)) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: 'Not a valid language in ISO-639-1 format',
|
||||
});
|
||||
return z.NEVER;
|
||||
}
|
||||
return val;
|
||||
}).optional().catch(undefined),
|
||||
});
|
||||
|
||||
const publicTimelineController: AppController = (c) => {
|
||||
const params = c.get('pagination');
|
||||
const { local, instance } = publicQuerySchema.parse(c.req.query());
|
||||
const { local, instance, language } = publicQuerySchema.parse(c.req.query());
|
||||
|
||||
const filter: NostrFilter = { kinds: [1], ...params };
|
||||
|
||||
|
|
@ -34,6 +45,10 @@ const publicTimelineController: AppController = (c) => {
|
|||
filter.search = `domain:${instance}`;
|
||||
}
|
||||
|
||||
if (language) {
|
||||
filter.search = filter.search + ' ' + `language:${language}`;
|
||||
}
|
||||
|
||||
return renderStatuses(c, [filter]);
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue