feat(bsky): add filter support for profile feeds (#17295)

This commit is contained in:
Tsuyumi 2024-10-25 07:43:45 +08:00 committed by GitHub
parent 97d0369d2e
commit b007418c5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 6 deletions

View File

@ -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],

View File

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