fix(bsky): keyword
This commit is contained in:
parent
9eae4eb8d7
commit
94160fa0f4
|
|
@ -415,6 +415,9 @@ export type Config = {
|
|||
smzdm: {
|
||||
cookie?: string;
|
||||
};
|
||||
bsky: {
|
||||
authorization?: string;
|
||||
};
|
||||
};
|
||||
|
||||
const value: Config | Record<string, any> = {};
|
||||
|
|
@ -870,6 +873,9 @@ const calculateValue = () => {
|
|||
smzdm: {
|
||||
cookie: envs.SMZDM_COOKIE,
|
||||
},
|
||||
bsky: {
|
||||
authorization: envs.BSKY_AUTHORIZATION,
|
||||
},
|
||||
};
|
||||
|
||||
for (const name in _value) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import { config } from '@/config';
|
||||
import ConfigNotFoundError from '@/errors/types/config-not-found';
|
||||
import { Route } from '@/types';
|
||||
import got from '@/utils/got';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/keyword/:keyword',
|
||||
|
|
@ -7,7 +9,13 @@ export const route: Route = {
|
|||
example: '/bsky/keyword/hello',
|
||||
parameters: { keyword: 'N' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requireConfig: [
|
||||
{
|
||||
name: 'BSKY_AUTHORIZATION',
|
||||
description: 'The authorization token for the Bluesky API',
|
||||
optional: false,
|
||||
},
|
||||
],
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
|
|
@ -15,22 +23,35 @@ export const route: Route = {
|
|||
supportScihub: false,
|
||||
},
|
||||
name: 'Keywords',
|
||||
maintainers: ['untitaker'],
|
||||
maintainers: ['untitaker', 'DIYgod'],
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
if (!config.bsky.authorization) {
|
||||
throw new ConfigNotFoundError('BSKY_AUTHORIZATION is not set');
|
||||
}
|
||||
|
||||
const keyword = ctx.req.param('keyword');
|
||||
const apiLink = `https://search.bsky.social/search/posts?q=${encodeURIComponent(keyword)}`;
|
||||
|
||||
const { data } = await got(apiLink);
|
||||
const data = await ofetch(`https://stinkhorn.us-west.host.bsky.network/xrpc/app.bsky.feed.searchPosts?q=${encodeURIComponent(keyword)}&limit=25&sort=latest`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${config.bsky.authorization}`,
|
||||
},
|
||||
});
|
||||
|
||||
const items = data.map((item) => ({
|
||||
title: item.post.text,
|
||||
link: `https://bsky.app/profile/${item.user.handle}/post/${item.tid.split('/')[1]}`,
|
||||
description: item.post.text,
|
||||
pubDate: new Date(item.post.createdAt / 1_000_000),
|
||||
author: item.user.handle,
|
||||
const items = data.posts.map((post) => ({
|
||||
title: post.record.text,
|
||||
link: `https://bsky.app/profile/${post.author.handle}/post/${post.uri.split('/').pop()}`,
|
||||
description: post.record.text,
|
||||
pubDate: new Date(post.record.createdAt),
|
||||
author: [
|
||||
{
|
||||
name: post.author.displayName,
|
||||
url: `https://bsky.app/profile/${post.author.handle}`,
|
||||
avatar: post.author.avatar,
|
||||
},
|
||||
],
|
||||
}));
|
||||
|
||||
return {
|
||||
|
|
|
|||
Loading…
Reference in New Issue