import { useState, useEffect } from 'react' import { useParams, Link } from 'react-router-dom' import ScriptViewer from '../components/ScriptViewer' import CommandCard from '../components/CommandCard' import { getScript } from '../lib/api' import { ScriptDetail as ScriptDetailType } from '../types' export default function ScriptDetail() { const { id } = useParams<{ id: string }>() const [script, setScript] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) useEffect(() => { if (!id) return getScript(id) .then(setScript) .catch((e) => setError(e instanceof Error ? e.message : '加载失败')) .finally(() => setLoading(false)) }, [id]) if (loading) { return (
加载中...
) } if (error || !script) { return (
😕

脚本不存在或已过期

{error}

创建新脚本
) } const command = `curl ${window.location.origin}/raw/${script.id} | ${script.runtime}` return (
← 返回首页

{script.id}

{script.runtime} {new Date(script.expires_at).toLocaleString('zh-CN')} 过期
删除此脚本
) }