Add ZIP download feature for repositories

- Add archive service to create ZIP files excluding gitignored files
- Add download endpoint to backend repo routes
- Add download button to repo cards with loading state
- Update README with new ZIP download feature
This commit is contained in:
Chris Scott committed 2025-12-12 20:48:38 -05:00
1 parent 725f782079
commit af9f645f30
7 files changed
+723 -10

No files matched your search

+19
View File
@@ -139,3 +139,22 @@ export async function listBranches(id: number): Promise<{ local: string[], remot
return response.json()
}
export async function downloadRepo(id: number, repoName: string): Promise<void> {
const response = await fetch(`${API_BASE_URL}/api/repos/${id}/download`)
if (!response.ok) {
const error = await response.json()
throw new Error(error.error || 'Failed to download repo')
}
const blob = await response.blob()
const url = window.URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.download = `${repoName}.zip`
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
window.URL.revokeObjectURL(url)
}
+31 -1
View File
@@ -1,8 +1,11 @@
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { Checkbox } from "@/components/ui/checkbox";
import { Loader2, Trash2, ExternalLink } from "lucide-react";
import { Loader2, Trash2, ExternalLink, Download } from "lucide-react";
import { useNavigate } from "react-router-dom";
import { downloadRepo } from "@/api/repos";
import { showToast } from "@/lib/toast";
import { BranchSwitcher } from "./BranchSwitcher";
@@ -31,6 +34,7 @@ export function RepoCard({
onSelect,
}: RepoCardProps) {
const navigate = useNavigate();
const [isDownloading, setIsDownloading] = useState(false);
const repoName = repo.repoUrl
? repo.repoUrl.split("/").slice(-1)[0].replace(".git", "")
@@ -127,6 +131,32 @@ export function RepoCard({
/>
)}
<Button
size="sm"
variant="outline"
onClick={async (e) => {
e.stopPropagation();
setIsDownloading(true);
try {
await downloadRepo(repo.id, repoName);
showToast.success("Download complete");
} catch (error: unknown) {
showToast.error(error instanceof Error ? error.message : "Download failed");
} finally {
setIsDownloading(false);
}
}}
disabled={!isReady || isDownloading}
className="h-10 sm:h-9 w-10 p-0"
title="Download as ZIP (excludes gitignored files)"
>
{isDownloading ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : (
<Download className="w-4 h-4" />
)}
</Button>
<Button
size="sm"
variant="destructive"