try add telebox
Browse files- src/App.tsx +144 -0
src/App.tsx
CHANGED
|
@@ -2624,6 +2624,67 @@ export default function App() {
|
|
| 2624 |
}
|
| 2625 |
};
|
| 2626 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2627 |
const remoteUploadFiles = async (fileList: FileList | null) => {
|
| 2628 |
if (!fileList?.length || !remoteUrl.trim()) return;
|
| 2629 |
for (const file of Array.from(fileList)) {
|
|
@@ -2858,6 +2919,7 @@ export default function App() {
|
|
| 2858 |
["encode", "Encode", queue.length, "queue"],
|
| 2859 |
["jobs", "Jobs", runningJobs.length, "running"],
|
| 2860 |
["remote", "Remote", remoteEntries.length, "entries"],
|
|
|
|
| 2861 |
] as [Tab, string, number, string][]).map(([value, label, count, meta]) => (
|
| 2862 |
<button
|
| 2863 |
key={value}
|
|
@@ -3497,6 +3559,88 @@ export default function App() {
|
|
| 3497 |
</div>
|
| 3498 |
</section>
|
| 3499 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3500 |
{tab === "encode" && (
|
| 3501 |
<section className="grid gap-6 xl:grid-cols-[minmax(0,1fr)_360px]">
|
| 3502 |
<div className="space-y-6">
|
|
|
|
| 2624 |
}
|
| 2625 |
};
|
| 2626 |
|
| 2627 |
+
const browseTelebox = async (dirPath?: string) => {
|
| 2628 |
+
const target = dirPath !== undefined ? dirPath : teleboxPath;
|
| 2629 |
+
setTeleboxLoading(true);
|
| 2630 |
+
setTeleboxError(null);
|
| 2631 |
+
try {
|
| 2632 |
+
const { entries, error } = await api.teleboxList(target);
|
| 2633 |
+
if (error) setTeleboxError(error);
|
| 2634 |
+
else {
|
| 2635 |
+
setTeleboxEntries(entries);
|
| 2636 |
+
setTeleboxPath(target);
|
| 2637 |
+
}
|
| 2638 |
+
} finally {
|
| 2639 |
+
setTeleboxLoading(false);
|
| 2640 |
+
}
|
| 2641 |
+
};
|
| 2642 |
+
|
| 2643 |
+
const toggleTeleboxSelected = (path: string) => {
|
| 2644 |
+
setTeleboxSelected(prev => prev.includes(path) ? prev.filter(p => p !== path) : [...prev, path]);
|
| 2645 |
+
};
|
| 2646 |
+
|
| 2647 |
+
const handleTeleboxUpload = async (fileList: FileList | null) => {
|
| 2648 |
+
if (!fileList) return;
|
| 2649 |
+
for (const file of Array.from(fileList)) {
|
| 2650 |
+
const { ok, error } = await api.teleboxUpload(file, teleboxPath);
|
| 2651 |
+
if (!ok) setToast(`Upload failed: ${error}`);
|
| 2652 |
+
}
|
| 2653 |
+
browseTelebox();
|
| 2654 |
+
};
|
| 2655 |
+
|
| 2656 |
+
const handleTeleboxDelete = async () => {
|
| 2657 |
+
if (!teleboxSelected.length) return;
|
| 2658 |
+
if (!confirm(`Delete ${teleboxSelected.length} item(s)?`)) return;
|
| 2659 |
+
for (const path of teleboxSelected) {
|
| 2660 |
+
const { ok, error } = await api.teleboxDelete(path);
|
| 2661 |
+
if (!ok) setToast(`Delete failed for ${path}: ${error}`);
|
| 2662 |
+
}
|
| 2663 |
+
setTeleboxSelected([]);
|
| 2664 |
+
browseTelebox();
|
| 2665 |
+
};
|
| 2666 |
+
|
| 2667 |
+
const handleTeleboxMove = async () => {
|
| 2668 |
+
const dest = prompt("Destination path:");
|
| 2669 |
+
if (!dest) return;
|
| 2670 |
+
for (const source of teleboxSelected) {
|
| 2671 |
+
const { ok, error } = await api.teleboxMove(source, dest + "/" + source.split("/").pop());
|
| 2672 |
+
if (!ok) setToast(`Move failed for ${source}: ${error}`);
|
| 2673 |
+
}
|
| 2674 |
+
browseTelebox();
|
| 2675 |
+
};
|
| 2676 |
+
|
| 2677 |
+
const handleTeleboxCopy = async () => {
|
| 2678 |
+
const dest = prompt("Destination path:");
|
| 2679 |
+
if (!dest) return;
|
| 2680 |
+
for (const source of teleboxSelected) {
|
| 2681 |
+
const { ok, error } = await api.teleboxCopy(source, dest + "/" + source.split("/").pop());
|
| 2682 |
+
if (!ok) setToast(`Copy failed for ${source}: ${error}`);
|
| 2683 |
+
}
|
| 2684 |
+
browseTelebox();
|
| 2685 |
+
};
|
| 2686 |
+
|
| 2687 |
+
|
| 2688 |
const remoteUploadFiles = async (fileList: FileList | null) => {
|
| 2689 |
if (!fileList?.length || !remoteUrl.trim()) return;
|
| 2690 |
for (const file of Array.from(fileList)) {
|
|
|
|
| 2919 |
["encode", "Encode", queue.length, "queue"],
|
| 2920 |
["jobs", "Jobs", runningJobs.length, "running"],
|
| 2921 |
["remote", "Remote", remoteEntries.length, "entries"],
|
| 2922 |
+
["telebox", "Telebox", teleboxEntries.length, "entries"],
|
| 2923 |
] as [Tab, string, number, string][]).map(([value, label, count, meta]) => (
|
| 2924 |
<button
|
| 2925 |
key={value}
|
|
|
|
| 3559 |
</div>
|
| 3560 |
</section>
|
| 3561 |
)}
|
| 3562 |
+
{tab === "telebox" && (
|
| 3563 |
+
<section className="grid gap-6">
|
| 3564 |
+
<div className="space-y-4">
|
| 3565 |
+
{/* Breadcrumb */}
|
| 3566 |
+
{teleboxBreadcrumbParts.length > 0 && (
|
| 3567 |
+
<div className="flex items-center gap-1 text-sm text-slate-600">
|
| 3568 |
+
<button type="button" onClick={() => { setTeleboxPath(""); browseTelebox(""); }} className="hover:underline">Root</button>
|
| 3569 |
+
{teleboxBreadcrumbParts.map((part, i, arr) => {
|
| 3570 |
+
const pathUpTo = "/" + arr.slice(0, i+1).join("/");
|
| 3571 |
+
return (
|
| 3572 |
+
<React.Fragment key={pathUpTo}>
|
| 3573 |
+
<span>/</span>
|
| 3574 |
+
<button type="button" onClick={() => { setTeleboxPath(pathUpTo); browseTelebox(pathUpTo); }} className="hover:underline font-medium">{part}</button>
|
| 3575 |
+
</React.Fragment>
|
| 3576 |
+
);
|
| 3577 |
+
})}
|
| 3578 |
+
</div>
|
| 3579 |
+
)}
|
| 3580 |
+
{/* Toolbar */}
|
| 3581 |
+
<div className="flex flex-wrap gap-2">
|
| 3582 |
+
<input ref={teleboxUploadRef} type="file" multiple className="hidden" onChange={(e) => handleTeleboxUpload(e.target.files)} />
|
| 3583 |
+
<button onClick={() => teleboxUploadRef.current?.click()} className="rounded-md bg-violet-600 px-4 py-2 text-sm font-medium text-white hover:bg-violet-700">Upload Files</button>
|
| 3584 |
+
<button onClick={() => { const name = prompt("Folder name:"); if (name) api.teleboxCreateFolder(teleboxPath ? `${teleboxPath}/${name}` : name).then(r => { if (r.ok) { browseTelebox(); } else { alert(r.error); } }); }} className="rounded-md bg-slate-200 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-300">New Folder</button>
|
| 3585 |
+
<button disabled={!teleboxSelected.length} onClick={handleTeleboxDelete} className="rounded-md bg-red-100 px-4 py-2 text-sm font-medium text-red-700 hover:bg-red-200 disabled:opacity-50">Delete Selected</button>
|
| 3586 |
+
<button disabled={!teleboxSelected.length} onClick={handleTeleboxMove} className="rounded-md bg-slate-200 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-300 disabled:opacity-50">Move Selected</button>
|
| 3587 |
+
<button disabled={!teleboxSelected.length} onClick={handleTeleboxCopy} className="rounded-md bg-slate-200 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-300 disabled:opacity-50">Copy Selected</button>
|
| 3588 |
+
</div>
|
| 3589 |
+
{/* Table */}
|
| 3590 |
+
<div className="overflow-x-auto rounded-xl border border-slate-200 bg-white shadow-sm">
|
| 3591 |
+
<table className="min-w-full text-sm">
|
| 3592 |
+
<thead className="bg-slate-50 text-xs uppercase text-slate-500">
|
| 3593 |
+
<tr>
|
| 3594 |
+
<th className="px-4 py-3 text-left"><input type="checkbox" onChange={(e) => setTeleboxSelected(e.target.checked ? teleboxEntries.map(e => e.path) : [])} /></th>
|
| 3595 |
+
<th className="px-4 py-3 text-left">Name</th>
|
| 3596 |
+
<th className="px-4 py-3 text-left">Size</th>
|
| 3597 |
+
<th className="px-4 py-3 text-left">Type</th>
|
| 3598 |
+
<th className="px-4 py-3 text-right">Actions</th>
|
| 3599 |
+
</tr>
|
| 3600 |
+
</thead>
|
| 3601 |
+
<tbody className="divide-y divide-slate-100">
|
| 3602 |
+
{teleboxLoading ? (
|
| 3603 |
+
<tr><td colSpan={5} className="px-4 py-14 text-center text-sm text-slate-400">Loading...</td></tr>
|
| 3604 |
+
) : !teleboxEntries.length ? (
|
| 3605 |
+
<tr><td colSpan={5} className="px-4 py-14 text-center text-sm text-slate-400">No entries</td></tr>
|
| 3606 |
+
) : (
|
| 3607 |
+
teleboxEntries.map((entry) => {
|
| 3608 |
+
const selected = teleboxSelected.includes(entry.path);
|
| 3609 |
+
return (
|
| 3610 |
+
<tr key={entry.path} className={selected ? "bg-violet-50/80" : "hover:bg-slate-50/70"}>
|
| 3611 |
+
<td className="px-4 py-3"><input type="checkbox" checked={selected} onChange={() => toggleTeleboxSelected(entry.path)} /></td>
|
| 3612 |
+
<td className="px-4 py-3">
|
| 3613 |
+
<div className="flex items-center gap-2 min-w-0">
|
| 3614 |
+
<span>{entry.isDir ? "📁" : "📄"}</span>
|
| 3615 |
+
{entry.isDir ? (
|
| 3616 |
+
<button type="button" onClick={() => { setTeleboxPath(entry.path); browseTelebox(entry.path); }} className="text-left text-sm font-medium text-violet-700 hover:underline truncate">
|
| 3617 |
+
{entry.name}
|
| 3618 |
+
</button>
|
| 3619 |
+
) : (
|
| 3620 |
+
<span className="text-sm font-medium text-slate-800 truncate">{entry.name}</span>
|
| 3621 |
+
)}
|
| 3622 |
+
</div>
|
| 3623 |
+
</td>
|
| 3624 |
+
<td className="px-4 py-3 text-sm text-slate-500">{entry.sizeStr || "-"}</td>
|
| 3625 |
+
<td className="px-4 py-3 text-sm text-slate-500"><span className={`inline-flex rounded-full px-2 py-0.5 text-xs font-semibold ${entry.isDir ? "bg-amber-100 text-amber-700" : "bg-slate-100 text-slate-600"}`}>{entry.isDir ? "folder" : (entry.type || "file")}</span></td>
|
| 3626 |
+
<td className="px-4 py-3 text-right">
|
| 3627 |
+
<div className="flex justify-end gap-1">
|
| 3628 |
+
{!entry.isDir && <button onClick={() => api.teleboxDownload(entry.path)} className="p-1 rounded hover:bg-slate-100" title="Download">⬇</button>}
|
| 3629 |
+
<button onClick={() => { const newName = prompt("Rename to:", entry.name); if (newName && newName !== entry.name) { api.teleboxRename(entry.path, newName).then(r => { if (r.ok) browseTelebox(); else alert(r.error); }); } }} className="p-1 rounded hover:bg-slate-100" title="Rename">✏</button>
|
| 3630 |
+
<button onClick={() => { if (confirm(`Delete ${entry.name}?`)) { api.teleboxDelete(entry.path).then(r => { if (r.ok) browseTelebox(); else alert(r.error); }); } }} className="p-1 rounded hover:bg-red-100 text-red-600" title="Delete">🗑</button>
|
| 3631 |
+
</div>
|
| 3632 |
+
</td>
|
| 3633 |
+
</tr>
|
| 3634 |
+
);
|
| 3635 |
+
})
|
| 3636 |
+
)}
|
| 3637 |
+
</tbody>
|
| 3638 |
+
</table>
|
| 3639 |
+
</div>
|
| 3640 |
+
</div>
|
| 3641 |
+
</section>
|
| 3642 |
+
)}
|
| 3643 |
+
|
| 3644 |
{tab === "encode" && (
|
| 3645 |
<section className="grid gap-6 xl:grid-cols-[minmax(0,1fr)_360px]">
|
| 3646 |
<div className="space-y-6">
|