Files
RSSHub/lib/routes/bsky/posts.ts
T
dependabot[bot]andTony 07834413f5 chore(deps-dev): bump eslint-plugin-unicorn from 64.0.0 to 65.0.0 (#22219)
* chore(deps-dev): bump eslint-plugin-unicorn from 64.0.0 to 65.0.0

Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 64.0.0 to 65.0.0.
- [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases)
- [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v64.0.0...v65.0.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-unicorn
  dependency-version: 65.0.0
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix: no-array-from-fill

* fix: unicorn-js/no-duplicate-set-values

* fix: no-this-outside-of-class

* fix: no-unnecessary-nested-ternary

* fix: prefer-array-last-methods

* fix: prefer-queue-microtask

* fix: prefer-split-limit

* fix: no-array-from-fill

* fix: no-unused-array-method-return

* fix: prefer-single-call

* fix: prefer-includes-over-repeated-comparisons

* fix: consistent-compound-words

* fix: prefer-includes-over-repeated-comparisons

* chore: add eslint-plugin-unicorn v65 recommended preset

* fix: correct duration parsing logic in parseDuration function

* fix: update oxlint-disable

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tony <TonyRL@users.noreply.github.com>
2026-06-09 00:08:15 +08:00

90 lines
3.1 KiB
TypeScript

import querystring from 'node:querystring';
import type { Route } from '@/types';
import { ViewType } from '@/types';
import cache from '@/utils/cache';
import { parseDate } from '@/utils/parse-date';
import { renderPost } from './templates/post';
import { getAuthorFeed, getProfile, resolveHandle } from './utils';
export const route: Route = {
path: '/profile/:handle/:routeParams?',
categories: ['social-media'],
view: ViewType.SocialMedia,
example: '/bsky/profile/bsky.app',
parameters: {
handle: 'User handle, can be found in URL',
routeParams: 'Filter parameter, Use filter to customize content types',
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['bsky.app/profile/:handle'],
},
],
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, filter, cache.tryGet);
const items = authorFeed.feed.map(({ post }) => ({
title: post.record.text.split('\n', 1)[0],
description: renderPost({
text: post.record.text.replaceAll('\n', '<br>'),
embed: post.embed,
// embed.$type "app.bsky.embed.record#view" and "app.bsky.embed.recordWithMedia#view" are not handled
}),
author: post.author.displayName,
pubDate: parseDate(post.record.createdAt),
link: `https://bsky.app/profile/${post.author.handle}/post/${post.uri.split('app.bsky.feed.post/', 2)[1]}`,
upvotes: post.likeCount,
comments: post.replyCount,
}));
ctx.set('json', {
DID,
profile,
authorFeed,
});
return {
title: `${profile.displayName} (@${profile.handle}) — Bluesky`,
description: profile.description?.replaceAll('\n', ' '),
link: `https://bsky.app/profile/${profile.handle}`,
image: profile.avatar,
icon: profile.avatar,
logo: profile.avatar,
item: items,
allowEmpty: true,
};
}