Skip to content

Commit

Permalink
feat: xlog summary
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Jul 7, 2023
1 parent bee9bac commit 16b3866
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
37 changes: 37 additions & 0 deletions src/app/api/xlog/summary/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { NextRequest } from 'next/server'

import { NextServerResponse } from '~/lib/edge-function.server'
import { getQueryClient } from '~/lib/query-client.server'

const headers = {
referer: `https://link.bilibili.com/p/center/index?visit_id=22ast2mb9zhc`,
'User-Agent': `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Shiro`,
}

export const GET = async (req: NextRequest) => {
const query = req.nextUrl.searchParams
const cid = query.get('cid')
const lang = query.get('lang') || 'zh'
if (!cid) {
return new NextServerResponse().status(400).end()
}

const queryClient = getQueryClient()
const res = await queryClient.fetchQuery({
queryKey: ['xlog-summary', cid],
queryFn: async () => {
return fetch(`https://xlog.app/api/summary?cid=${cid}&lang=${lang}`, {
headers: new Headers(headers),
})
.then((res) => res.json())
.catch(() => null)
},
})

const response = new NextServerResponse()
if (!res) {
return response.status(400).end()
}

return response.json({ ...res })
}
1 change: 0 additions & 1 deletion src/components/ui/link-card/LinkCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export interface LinkCardProps {
}

export const LinkCard = (props: LinkCardProps) => {
console.log('LinkCard', props)
const isClient = useIsClientTransition()

if (!isClient) return null
Expand Down
14 changes: 5 additions & 9 deletions src/components/widgets/xlog/XLogSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { FC, ReactNode, SVGProps } from 'react'
import { AutoResizeHeight } from '~/components/widgets/shared/AutoResizeHeight'
import { useIsClient } from '~/hooks/common/use-is-client'
import { clsxm } from '~/lib/helper'
import { apiClient } from '~/lib/request'
import { useCurrentNoteDataSelector } from '~/providers/note/CurrentNoteDataProvider'
import { useCurrentPostDataSelector } from '~/providers/post/CurrentPostDataProvider'

Expand All @@ -17,14 +16,11 @@ const XLogSummary: FC<{
[`getSummary`, cid],
async ({ queryKey }) => {
const [, cid] = queryKey
return apiClient.proxy.fn.xlog.get_summary.get<{
data: string
}>({
params: {
cid,
lang: 'zh',
},
})
const data = await fetch(`/api/xlog/summary?cid=${cid}`).then((res) =>
res.json(),
)
if (!data) throw new Error('请求错误')
return data
},
{
enabled: !!cid,
Expand Down

1 comment on commit 16b3866

@vercel
Copy link

@vercel vercel bot commented on 16b3866 Jul 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

shiro – ./

innei.in
shiro-innei.vercel.app
springtide.vercel.app
shiro-git-main-innei.vercel.app

Please sign in to comment.