Skip to content

Commit

Permalink
first commit for github-repo-download through api
Browse files Browse the repository at this point in the history
  • Loading branch information
itsarghyadas committed Apr 28, 2024
0 parents commit a7f7c8d
Show file tree
Hide file tree
Showing 17 changed files with 5,349 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GITHUB_ACCESS_TOKEN=""
NEXT_PUBLIC_URL=""
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
30 changes: 30 additions & 0 deletions app/api/repo/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { NextRequest, NextResponse } from "next/server";
import { Octokit } from "octokit";

const octokit = new Octokit({
auth: process.env.GITHUB_ACCESS_TOKEN,
});

export async function POST() {
try {
const response = await octokit.request(
"GET /repos/{owner}/{repo}/zipball",
{
owner: "repo__owner__example__[itsarghyadas]",
repo: "repo_name__example__[github-repo-download-api]",
headers: {
"X-GitHub-Api-Version": "2022-11-28",
},
}
);
const status = response.status;
const downloadUrl = response.url;
return NextResponse.json({ success: true, status, downloadUrl });
} catch (error) {
console.error("Error fetching repository zipball:", error);
return NextResponse.json(
{ success: false, error: "Failed to fetch repository zipball." },
{ status: 500 }
);
}
}
Binary file added app/favicon.ico
Binary file not shown.
67 changes: 67 additions & 0 deletions app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
.bg-pattern::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
background-color: #e5e5f7;
opacity: 0.15;
background-image: linear-gradient(
30deg,
#444cf7 12%,
transparent 12.5%,
transparent 87%,
#444cf7 87.5%,
#444cf7
),
linear-gradient(
150deg,
#444cf7 12%,
transparent 12.5%,
transparent 87%,
#444cf7 87.5%,
#444cf7
),
linear-gradient(
30deg,
#444cf7 12%,
transparent 12.5%,
transparent 87%,
#444cf7 87.5%,
#444cf7
),
linear-gradient(
150deg,
#444cf7 12%,
transparent 12.5%,
transparent 87%,
#444cf7 87.5%,
#444cf7
),
linear-gradient(
60deg,
#444cf777 25%,
transparent 25.5%,
transparent 75%,
#444cf777 75%,
#444cf777
),
linear-gradient(
60deg,
#444cf777 25%,
transparent 25.5%,
transparent 75%,
#444cf777 75%,
#444cf777
);
background-size: 20px 35px;
background-position: 0 0, 0 0, 10px 18px, 10px 18px, 0 0, 10px 18px;
}
}
22 changes: 22 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Metadata } from "next";
import { Gabarito } from "next/font/google";
import "./globals.css";

const gabarito = Gabarito({ subsets: ["latin"] });

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};

export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body className={gabarito.className}>{children}</body>
</html>
);
}
59 changes: 59 additions & 0 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"use client";
import axios from "axios";
import { useState } from "react";
const webUrl = process.env.NEXT_PUBLIC_URL;

export default function Page() {
const [loading, setLoading] = useState(false);

const handleDownload = () => {
console.log("download");
setLoading(true);
axios
.post(`${webUrl}/api/repo`)
.then((response) => {
const downloadUrl = response.data.downloadUrl;
const status = response.data.status;
window.location.href = downloadUrl;
})
.catch((error) => {
console.log("error", error);
})
.finally(() => {
setLoading(false);
});
};

return (
<section className="bg-pattern relative isolate min-h-screen flex items-center justify-center">
<div className="border rounded-xl bg-indigo-600 ring-2 ring-offset-2 ring-indigo-500/50 p-20 flex flex-col gap-y-7 items-center justify-center">
<p className="font-bold text-3xl tracking-tighter text-white">
Github Repo Download API
</p>
<button
className="bg-white w-full flex items-center gap-x-3 justify-center h-12 text-neutral-900 text-lg font-bold rounded-md hover:bg-neutral-100"
onClick={handleDownload}
disabled={loading}
>
{loading ? "Downloading..." : "Download Repo"}
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className="lucide lucide-cloud-download"
>
<path d="M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242" />
<path d="M12 12v9" />
<path d="m8 17 4 4 4-4" />
</svg>
</button>
</div>
</section>
);
}
4 changes: 4 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {}

module.exports = nextConfig
Loading

0 comments on commit a7f7c8d

Please sign in to comment.