feat: add tweet fallback
This commit is contained in:
parent
3edf43af7c
commit
4327e85a5b
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"latest": [
|
||||
151, 53994, 54570, 54481, 54537, 54302, 53944, 55768, 55855, 56592, 54986,
|
||||
56875, 56873, 56666, 55996, 57407, 56249, 57858, 56973, 58600
|
||||
56875, 56873, 56666, 55996, 57407, 56249, 57858, 56973, 58600, 57399
|
||||
],
|
||||
"comment": [54986],
|
||||
"comment_content": ["snowcherryblossom"]
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export async function GET(req: Request): Promise<Response> {
|
|||
const tweet = (await cacheGet({
|
||||
key: `tweet/${tweetId}`,
|
||||
noUpdate: true,
|
||||
expireTime: 60 * 60 * 24 * 3,
|
||||
noExpire: true,
|
||||
getValueFun: async () => await getTweet(tweetId),
|
||||
})) as Tweet | undefined
|
||||
return res.status(tweet ? 200 : 404).json({ data: tweet ?? null })
|
||||
|
|
|
|||
|
|
@ -11,13 +11,20 @@ const components: TwitterComponents = {
|
|||
MediaImg: (props) => <Image {...props} fill unoptimized alt="tweet-media" />,
|
||||
}
|
||||
|
||||
export default function Tweet({ id }: { id: string }) {
|
||||
export default function Tweet({
|
||||
id,
|
||||
fullUrl,
|
||||
}: {
|
||||
id: string
|
||||
fullUrl: string
|
||||
}) {
|
||||
return (
|
||||
<div className="flex justify-center">
|
||||
<ReactTweet
|
||||
id={id}
|
||||
components={components}
|
||||
apiUrl={`${SITE_URL}/api/tweet?id=${id}`}
|
||||
fallback={<>{fullUrl}</>}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,12 +8,15 @@ export const TweetTransformer: Transformer = {
|
|||
shouldTransform(url) {
|
||||
const { host, pathname } = url
|
||||
|
||||
return isHostIncludes("twitter.com", host) && pathname.includes("/status/")
|
||||
return (
|
||||
(isHostIncludes("twitter.com", host) || isHostIncludes("x.com", host)) &&
|
||||
pathname.includes("/status/")
|
||||
)
|
||||
},
|
||||
getHTML(url) {
|
||||
const { pathname } = url
|
||||
const matched = match<{ id: string }>("/:user/status/:id")(pathname)
|
||||
if (!matched) return
|
||||
return `<tweet id="${matched.params.id}" />`
|
||||
return `<tweet id="${matched.params.id}" fullUrl="${url}" />`
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue