diff --git a/lib/routes/dingshao/namespace.ts b/lib/routes/dingshao/namespace.ts new file mode 100644 index 00000000000000..76efa9916dfa86 --- /dev/null +++ b/lib/routes/dingshao/namespace.ts @@ -0,0 +1,7 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '盯梢', + url: 'www.dingshao.cn', + lang: 'zh-CN', +}; diff --git a/lib/routes/dingshao/share.ts b/lib/routes/dingshao/share.ts new file mode 100644 index 00000000000000..371edb20c9ad5b --- /dev/null +++ b/lib/routes/dingshao/share.ts @@ -0,0 +1,53 @@ +import { Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { parseDate } from '@/utils/parse-date'; +import type { Context } from 'hono'; +import { Value } from './types'; + +export const route: Route = { + path: '/share/:shortId', + categories: ['other'], + example: '/dingshao/share/FzFypN', + parameters: { + shortId: '频道 ID', + }, + radar: [ + { + source: ['www.dingshao.cn/share/:shortId'], + }, + ], + name: '频道', + maintainers: ['TonyRL'], + handler, +}; + +const baseUrl = 'https://www.dingshao.cn'; + +async function handler(ctx: Context) { + const { shortId } = ctx.req.param(); + + const response = await ofetch(`${baseUrl}/api/v2/channel/get-channel-and-recent-messages-by-short-id`, { + method: 'POST', + body: { + shortId, + }, + }); + + const items = response.value.bundle.channelMessages.map((message) => ({ + title: message.excerpt.split('\n')[0], + description: message.content, + pubDate: parseDate(message.publishedAt), + category: message.tags, + link: `${baseUrl}/channel/${response.value.channel}/${message.id}`, + })); + + const channelProfile = response.value.bundle.channels.find((channel) => channel.id === response.value.channel)?.profile; + + return { + title: channelProfile?.name, + description: channelProfile?.description, + link: `${baseUrl}/share/${shortId}`, + image: channelProfile?.image, + item: items, + }; +} diff --git a/lib/routes/dingshao/types.ts b/lib/routes/dingshao/types.ts new file mode 100644 index 00000000000000..df0b92780d7f1a --- /dev/null +++ b/lib/routes/dingshao/types.ts @@ -0,0 +1,64 @@ +export interface Value { + value: { + channel: string; + recentMessages: string[]; + bundle: Bundle; + }; +} + +interface Bundle { + channels: Channel[]; + users: User[]; + channelMessages: ChannelMessage[]; + channelMessageInteractions: any[]; +} + +interface Channel { + id: string; + owner: string; + profile: Profile; + tags: string[]; + script: Script; + private: boolean; + stats: Stats; + sharable: boolean; + lastPublishedAt: string; +} + +interface Profile { + name: string; + description: string; + image: string; +} + +interface Script { + homepage: string; +} + +interface Stats { + subscribers: number; +} + +interface User { + id: string; + profile: UserProfile; +} + +interface UserProfile { + name: string; + image: string; +} + +interface ChannelMessage { + id: string; + channel: string; + author: string; + tags: string[]; + excerpt: string; + content: string; + likes: number; + private: boolean; + sharable: boolean; + script: boolean; + publishedAt: string; +}