feat(bsky): add filter support for profile feeds (#17295)
This commit is contained in:
parent
97d0369d2e
commit
b007418c5a
|
|
@ -7,13 +7,17 @@ import { parseDate } from '@/utils/parse-date';
|
|||
import { resolveHandle, getProfile, getAuthorFeed } from './utils';
|
||||
import { art } from '@/utils/render';
|
||||
import path from 'node:path';
|
||||
import querystring from 'querystring';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/profile/:handle',
|
||||
path: '/profile/:handle/:routeParams?',
|
||||
categories: ['social-media', 'popular'],
|
||||
view: ViewType.SocialMedia,
|
||||
example: '/bsky/profile/bsky.app',
|
||||
parameters: { handle: 'User handle, can be found in URL' },
|
||||
parameters: {
|
||||
handle: 'User handle, can be found in URL',
|
||||
routeParams: 'Filter parameter, Use filter to customize content types',
|
||||
},
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
|
|
@ -30,13 +34,28 @@ export const route: Route = {
|
|||
name: 'Post',
|
||||
maintainers: ['TonyRL'],
|
||||
handler,
|
||||
description: `
|
||||
| Filter Value | Description |
|
||||
|--------------|-------------|
|
||||
| posts_with_replies | Includes Posts, Replies, and Reposts |
|
||||
| posts_no_replies | Includes Posts and Reposts, without Replies |
|
||||
| posts_with_media | Shows only Posts containing media |
|
||||
| posts_and_author_threads | Shows Posts and Threads, without Replies and Reposts |
|
||||
|
||||
Default value for filter is \`posts_and_author_threads\` if not specified.
|
||||
|
||||
Example:
|
||||
- \`/bsky/profile/bsky.app/filter=posts_with_replies\``,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const handle = ctx.req.param('handle');
|
||||
const routeParams = querystring.parse(ctx.req.param('routeParams'));
|
||||
const filter = routeParams.filter || 'posts_and_author_threads';
|
||||
|
||||
const DID = await resolveHandle(handle, cache.tryGet);
|
||||
const profile = await getProfile(DID, cache.tryGet);
|
||||
const authorFeed = await getAuthorFeed(DID, cache.tryGet);
|
||||
const authorFeed = await getAuthorFeed(DID, filter, cache.tryGet);
|
||||
|
||||
const items = authorFeed.feed.map(({ post }) => ({
|
||||
title: post.record.text.split('\n')[0],
|
||||
|
|
|
|||
|
|
@ -28,14 +28,14 @@ const getProfile = (did, tryGet) =>
|
|||
});
|
||||
|
||||
// https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/getAuthorFeed.json
|
||||
const getAuthorFeed = (did, tryGet) =>
|
||||
const getAuthorFeed = (did, filter, tryGet) =>
|
||||
tryGet(
|
||||
`bsky:authorFeed:${did}`,
|
||||
`bsky:authorFeed:${did}:${filter}`,
|
||||
async () => {
|
||||
const { data } = await got('https://public.api.bsky.app/xrpc/app.bsky.feed.getAuthorFeed', {
|
||||
searchParams: {
|
||||
actor: did,
|
||||
filter: 'posts_and_author_threads',
|
||||
filter,
|
||||
limit: 30,
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue