Spaces:
Running
Running
Download frontend/src/components/FileInspectorDrawer.tsx from TwanAPI/UploadFile: direct link, hf CLI and curl.
- Browser
- Download file 5.7 kB
-
https://huggingface.co/spaces/TwanAPI/UploadFile/resolve/main/frontend/src/components/FileInspectorDrawer.tsx
- Command line
-
hf download hf://spaces/TwanAPI/UploadFile/frontend/src/components/FileInspectorDrawer.tsx
-
curl -L -o FileInspectorDrawer.tsx https://huggingface.co/spaces/TwanAPI/UploadFile/resolve/main/frontend/src/components/FileInspectorDrawer.tsx
5.7 kB
| "use client"; | |
| import React from "react"; | |
| import { Info, X, Eye, Download, Edit3, Trash2, Share2 } from "lucide-react"; | |
| import { useCloud } from "@/context/CloudContext"; | |
| import { formatBytes } from "@/lib/api"; | |
| export function FileInspectorDrawer() { | |
| const { | |
| inspectedFile, | |
| setInspectedFile, | |
| getDownloadUrl, | |
| setPreviewFile, | |
| triggerDownload, | |
| sharesMap, | |
| setShareTarget, | |
| canRename, | |
| canDelete, | |
| setRenameTarget, | |
| setNewPathInput, | |
| handleDeleteFile, | |
| } = useCloud(); | |
| if (!inspectedFile) return null; | |
| const fileShare = sharesMap[inspectedFile.path]; | |
| const pendingCount = | |
| fileShare?.enabled && Array.isArray(fileShare.requests) | |
| ? fileShare.requests.filter((r) => r.status === "pending").length | |
| : 0; | |
| return ( | |
| <aside className="w-80 shrink-0 glass rounded-3xl p-5 border border-white/10 flex flex-col justify-between h-fit sticky top-24"> | |
| <div className="space-y-4"> | |
| <div className="flex items-center justify-between border-b border-white/10 pb-3"> | |
| <span className="text-xs font-bold uppercase tracking-wider text-indigo-300 flex items-center gap-1.5"> | |
| <Info className="w-4 h-4" /> Chi tiết Tệp tin | |
| </span> | |
| <button | |
| onClick={() => setInspectedFile(null)} | |
| className="p-1 rounded-lg hover:bg-white/10 text-slate-400" | |
| > | |
| <X className="w-4 h-4" /> | |
| </button> | |
| </div> | |
| {/* Mini Media Thumbnail if video or image */} | |
| {inspectedFile.category === "video" ? ( | |
| <video | |
| controls | |
| src={getDownloadUrl(inspectedFile.path, true)} | |
| className="w-full rounded-2xl bg-black border border-white/10 max-h-44" | |
| /> | |
| ) : inspectedFile.category === "image" ? ( | |
| <img | |
| src={getDownloadUrl(inspectedFile.path, true)} | |
| alt={inspectedFile.name} | |
| className="w-full rounded-2xl object-cover max-h-44 border border-white/10" | |
| /> | |
| ) : null} | |
| <div> | |
| <h4 className="text-sm font-bold text-white break-all">{inspectedFile.name}</h4> | |
| <p className="text-xs font-mono text-slate-400 mt-1 break-all"> | |
| cloud://thtuanit/{inspectedFile.path} | |
| </p> | |
| </div> | |
| <div className="p-3.5 rounded-2xl bg-slate-900/90 border border-white/5 space-y-2 text-xs font-mono"> | |
| <div className="flex justify-between"> | |
| <span className="text-slate-400">Người sở hữu:</span> | |
| <span className="text-indigo-300 font-bold">@{inspectedFile.owner}</span> | |
| </div> | |
| <div className="flex justify-between"> | |
| <span className="text-slate-400">Dung lượng:</span> | |
| <span className="text-white">{formatBytes(inspectedFile.size)}</span> | |
| </div> | |
| <div className="flex justify-between"> | |
| <span className="text-slate-400">Bytes:</span> | |
| <span className="text-slate-300">{inspectedFile.size.toLocaleString()}</span> | |
| </div> | |
| <div className="flex justify-between"> | |
| <span className="text-slate-400">Cập nhật:</span> | |
| <span className="text-slate-300">{inspectedFile.updatedAt || "N/A"}</span> | |
| </div> | |
| </div> | |
| <div className="space-y-2 pt-2"> | |
| <button | |
| onClick={() => setShareTarget(inspectedFile)} | |
| className="w-full py-2.5 rounded-xl bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-500 hover:to-teal-500 text-xs font-bold text-white flex items-center justify-center gap-2 transition shadow-lg shadow-emerald-600/20" | |
| > | |
| <Share2 className="w-4 h-4" /> | |
| <span> | |
| {fileShare?.enabled | |
| ? pendingCount > 0 | |
| ? `Quản lý Link Share (${pendingCount} chờ duyệt)` | |
| : "Đang chia sẻ • Quản lý Link" | |
| : "Chia sẻ nhanh qua Link"} | |
| </span> | |
| </button> | |
| <button | |
| onClick={() => setPreviewFile(inspectedFile)} | |
| className="w-full py-2.5 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-xs font-bold text-white flex items-center justify-center gap-2 transition" | |
| > | |
| <Eye className="w-4 h-4" /> Mở Trình phát Toàn màn hình | |
| </button> | |
| <button | |
| onClick={() => triggerDownload(inspectedFile)} | |
| className="w-full py-2.5 rounded-xl bg-white/10 hover:bg-white/15 text-xs font-semibold text-slate-200 flex items-center justify-center gap-2 transition" | |
| > | |
| <Download className="w-4 h-4" /> Tải tệp về máy | |
| </button> | |
| {canRename && ( | |
| <button | |
| onClick={() => { | |
| setRenameTarget(inspectedFile); | |
| setNewPathInput(inspectedFile.path); | |
| }} | |
| className="w-full py-2.5 rounded-xl bg-amber-500/15 hover:bg-amber-500/25 border border-amber-500/30 text-xs font-semibold text-amber-300 flex items-center justify-center gap-2 transition" | |
| > | |
| <Edit3 className="w-4 h-4" /> Đổi tên / Di chuyển | |
| </button> | |
| )} | |
| {canDelete && ( | |
| <button | |
| onClick={() => handleDeleteFile(inspectedFile)} | |
| className="w-full py-2.5 rounded-xl bg-rose-500/15 hover:bg-rose-500/25 border border-rose-500/30 text-xs font-semibold text-rose-300 flex items-center justify-center gap-2 transition" | |
| > | |
| <Trash2 className="w-4 h-4" /> Xóa khỏi Kho lưu trữ | |
| </button> | |
| )} | |
| </div> | |
| </div> | |
| </aside> | |
| ); | |
| } | |