Spaces:
TwanAPI
/
Running

ddosvn's picture
Deploy clean-slate Next.js FE (Feature-Based Architecture, Swiss-Obsidian UI/UX, CWV, SEO, AI Discovery)
968ca90 verified
Raw History Blame Contribute Delete
5.71 kB
"use client";
import React from "react";
import { Copy, FileCode2, KeyRound } from "lucide-react";
import { useAuth } from "@/features/auth";
import { PublicFooter, PublicHeader } from "@/features/landing";
import { WorkspaceLayout } from "@/features/workspace";
import { SITE_URL } from "@/shared/config/site";
import { Badge, Button, useToast } from "@/shared/ui";
export function DevelopersView() {
const { token, user } = useAuth();
const { notify } = useToast();
const bearerPlaceholder = token || "<YOUR_BEARER_TOKEN_OR_API_KEY>";
const snippets = [
{
title: "1. Liệt kê danh sách tệp",
method: "GET /api/files",
code: `curl -s "${SITE_URL}/api/files" \\\n -H "Authorization: Bearer ${bearerPlaceholder}"`,
},
{
title: "2. Tải tệp lên (Multipart Streaming tới 10 GiB)",
method: "POST /api/upload",
code: `curl -X POST "${SITE_URL}/api/upload" \\\n -H "Authorization: Bearer ${bearerPlaceholder}" \\\n -F "path=media/video.mp4" \\\n -F "file=@./video.mp4"`,
},
{
title: "3. Đổi tên / Di chuyển đường dẫn (Zero-Copy Hash)",
method: "PUT /api/files",
code: `curl -X PUT "${SITE_URL}/api/files" \\\n -H "Authorization: Bearer ${bearerPlaceholder}" \\\n -H "Content-Type: application/json" \\\n -d '{"old_path":"media/video.mp4","new_path":"archive/video-2026.mp4"}'`,
},
{
title: "4. Tải xuống hoặc Stream HTTP 206 Range",
method: "GET /api/download",
code: `curl -L "${SITE_URL}/api/download?path=archive/video-2026.mp4" \\\n -H "Authorization: Bearer ${bearerPlaceholder}" \\\n -o video-2026.mp4`,
},
];
const bodyContent = (
<div className="p-4 sm:p-6 lg:p-8 max-w-6xl mx-auto w-full space-y-6">
<div className="surface-panel rounded-2xl p-6 sm:p-8 space-y-4">
<div className="flex flex-wrap items-center justify-between gap-3">
<Badge tone="cyan">
<FileCode2 className="w-3.5 h-3.5" aria-hidden="true" />
<span>REST API &amp; AGENTIC DISCOVERY</span>
</Badge>
<div className="flex flex-wrap items-center gap-3 text-xs font-mono">
<a href="/llms.txt" className="text-sky-400 hover:underline">
/llms.txt
</a>
<a href="/llms-full.txt" className="text-sky-400 hover:underline">
/llms-full.txt
</a>
<a href="/.well-known/openapi.json" className="text-emerald-400 hover:underline">
/.well-known/openapi.json
</a>
</div>
</div>
<h1 className="text-2xl sm:text-3xl font-extrabold text-white tracking-tight">
Tài liệu Tích hợp REST API &amp; Bearer Token
</h1>
<p className="text-xs sm:text-sm text-slate-300 leading-relaxed max-w-3xl">
Sử dụng Session Bearer Token (HMAC-SHA256, hiệu lực 7 ngày sau khi đăng nhập) hoặc{" "}
<code className="text-sky-300">Authorization: Bearer &lt;API_KEY&gt;</code> /{" "}
<code className="text-sky-300">X-API-Key</code> (quyền Admin vĩnh viễn) để tự động hóa
lưu trữ qua CLI, CI/CD hoặc AI Agent.
</p>
{token && (
<div className="p-4 rounded-xl bg-slate-950/90 border border-slate-800 flex flex-col sm:flex-row sm:items-center justify-between gap-3">
<div className="min-w-0">
<p className="text-[11px] font-mono text-slate-400 flex items-center gap-1.5">
<KeyRound className="w-3.5 h-3.5 text-emerald-400" aria-hidden="true" />
<span>BEARER TOKEN HIỆN TẠI CỦA BẠN (7 NGÀY)</span>
</p>
<p className="text-xs font-mono text-emerald-300 truncate mt-1">{token}</p>
</div>
<Button
variant="secondary"
size="sm"
onClick={() => {
navigator.clipboard.writeText(token);
notify("Đã sao chép Bearer Token!", "success");
}}
>
<Copy className="w-3.5 h-3.5" aria-hidden="true" />
<span>Sao chép Token</span>
</Button>
</div>
)}
</div>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-5">
{snippets.map((item) => (
<article key={item.method} className="surface-card rounded-2xl p-5 space-y-3">
<div className="flex items-center justify-between gap-2">
<h2 className="text-sm font-bold text-white">{item.title}</h2>
<Badge tone="cyan">{item.method}</Badge>
</div>
<pre className="p-4 rounded-xl bg-slate-950 border border-slate-800/90 text-xs font-mono text-slate-200 overflow-x-auto leading-relaxed">
{item.code}
</pre>
<div className="flex justify-end">
<Button
variant="ghost"
size="sm"
onClick={() => {
navigator.clipboard.writeText(item.code);
notify(`Đã sao chép lệnh ${item.method}`, "success");
}}
>
<Copy className="w-3.5 h-3.5" aria-hidden="true" />
<span>Sao chép cURL</span>
</Button>
</div>
</article>
))}
</div>
</div>
);
if (user) {
return <WorkspaceLayout>{bodyContent}</WorkspaceLayout>;
}
return (
<div className="min-h-screen flex flex-col bg-dot-grid">
<PublicHeader />
<main id="main-content" className="flex-1 py-6">
{bodyContent}
</main>
<PublicFooter />
</div>
);
}