Skip to content

Commit

Permalink
fix: remove download api route
Browse files Browse the repository at this point in the history
  • Loading branch information
dillionverma committed Oct 18, 2024
1 parent efc64a9 commit 12d8631
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 64 deletions.
34 changes: 0 additions & 34 deletions app/api/repo/download/route.tsx

This file was deleted.

37 changes: 8 additions & 29 deletions components/repo-download.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,27 @@
"use client";

import { useState } from "react";
import Link from "next/link";
import { ArrowRightIcon, Download } from "lucide-react";
import Link from "next/link";
import { useState } from "react";
import { toast } from "sonner";

import { cn } from "@/lib/utils";
import { Button, buttonVariants } from "@/components/ui/button";
import { Icons } from "@/components/icons";
import { Button, buttonVariants } from "@/components/ui/button";
import { cn } from "@/lib/utils";

interface RepoDownloadProps {
repo: string;
owner: string;
url: string;
free?: boolean;
}

export default function RepoDownload({
repo,
owner,
free = false,
}: RepoDownloadProps) {
export default function RepoDownload({ url, free = false }: RepoDownloadProps) {
const [loading, setLoading] = useState(false);

const handleDownload = async () => {
setLoading(true);

try {
const response = await fetch(
`${process.env.NEXT_PUBLIC_APP_URL}/api/repo/download`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ repo, owner }),
},
);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
const downloadUrl = data.downloadUrl;
/* window.open(downloadUrl, "_blank"); */
window.location.href = downloadUrl;
window.location.href = url;
} catch (error) {
toast.error("Error occured while downloading. Please try again.");
console.error("error", error);
Expand Down Expand Up @@ -73,7 +52,7 @@ export default function RepoDownload({
buttonVariants({
variant: "default",
}),
"not-prose group relative w-full gap-1",
"not-prose group relative w-full gap-1"
)}
>
Buy Now
Expand Down
5 changes: 4 additions & 1 deletion content/docs/templates/portfolio.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ published: true
className="w-full rounded-xl border shadow-2xl"
/>
<div className="flex w-full flex-col gap-2 sm:flex-row">
<RepoDownload repo={"portfolio"} owner={"dillionverma"} free />
<RepoDownload
url="https://codeload.github.com/dillionverma/portfolio/legacy.zip/refs/heads/main"
free
/>
<TemplatePreview href="https://portfolio-magicui.vercel.app/">
Live Preview{" "}
</TemplatePreview>
Expand Down

0 comments on commit 12d8631

Please sign in to comment.