Spaces:
TwanAPI
/
Running

File size: 5,708 Bytes
968ca90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"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>
  );
}