import Link from 'next/link' import {ArrowLeft, ArrowUpRight, FileCode2, RefreshCw, Terminal} from 'lucide-react' import {languageLabel, rawSnippetUrl} from '@/lib/snippet-utils' import {SnippetEditor} from '@/components/snippet-editor' const API_BASE = 'https://snippets.rtast.cn' type Snippet = { createdAt?: string; filename: string; content: string } async function getSnippet(id: string): Promise<{ data?: Snippet; status: number }> { try { const response = await fetch(`${API_BASE}/${encodeURIComponent(id)}`, {cache: 'no-store'}) if (!response.ok) return {status: response.status} return {data: await response.json(), status: response.status} } catch { return {status: 503} } } export default async function ReaderPage({params}: { params: Promise<{ snippet_id: string }> }) { const {snippet_id: id} = await params const result = await getSnippet(id) const snippet = result.data const message = result.status === 404 ? 'This snippet does not exist or has expired.' : 'The snippet server could not be reached.' return (
KSnippets New snippet
{snippet ? <>

snippet / {id}

{snippet.filename}

{snippet.createdAt ? new Date(snippet.createdAt).toLocaleString() : 'Published snippet'} ยท {languageLabel(snippet.filename)}

Open raw
{snippet.content.split('\n').length} lines
:
{result.status === 404 ? '404' : }

{result.status === 404 ? 'Snippet not found' : 'Connection error'}

{message}

Create a snippet{result.status !== 404 && Try again}
}
) }