| 1 | import { notFound } from "next/navigation"; |
| 2 | |
| 3 | import { createServerClient } |
| 4 | import { codeSearchStats, ogCard |
| 5 | |
| 6 | /** The card for a repository's code search, which needs the query an `opengraph-image` never sees. */ |
| 7 | export async function GET |
| 8 | request: Request |
| 9 | { params }: |
| 10 | ) { |
| 11 | const { username, |
| 12 | const query = |
| 13 | const client = |
| 14 | |
| 15 | if (!query) |
| 16 | // A private repository answers 404 to the crawler, so nothing leaks here. |
| 17 | const { data |
| 18 | params: { path: { |
| 19 | }); |
| 20 | if (!data) |
| 21 | |
| 22 | return ogCard({ |
| 23 | eyebrow: `${username} |
| 24 | icon: "search", |
| 25 | title: "Search code", |
| 26 | description: `Search the code of ${data |
| 27 | }); |
| 28 | } |
| 29 | |
| 30 | const { data, |
| 31 | "/api/repositories/{username}/{slug}/search", |
| 32 | { params: { path: |
| 33 | ); |
| 34 | if (response.status |
| 35 | |
| 36 | return ogCard({ |
| 37 | eyebrow: `${username} |
| 38 | icon: "search", |
| 39 | badge: { label: " |
| 40 | title: `“${query |
| 41 | description: `Matches in ${username |
| 42 | // a query zoekt rejects, or zoekt being down, still gets a card, just without numbers |
| 43 | stats: data ? |
| 44 | }); |
| 45 | } |