From b254cb83f4303866e379745610b2f3d158664e46 Mon Sep 17 00:00:00 2001
From: Shivam Ross <144504100+shivam-ross@users.noreply.github.com>
Date: Wed, 12 Mar 2025 19:41:24 +0530
Subject: [PATCH 1/7] added githubcard
---
.../apps/frontend/components/Githubcard.tsx | 87 +++++++++++++++++++
1 file changed, 87 insertions(+)
create mode 100644 mobile-magic/apps/frontend/components/Githubcard.tsx
diff --git a/mobile-magic/apps/frontend/components/Githubcard.tsx b/mobile-magic/apps/frontend/components/Githubcard.tsx
new file mode 100644
index 0000000..5fe578f
--- /dev/null
+++ b/mobile-magic/apps/frontend/components/Githubcard.tsx
@@ -0,0 +1,87 @@
+'use client'
+import { useState } from "react";
+import { ChevronDown, ChevronUp, ExternalLink } from "lucide-react";
+import { BACKEND_URL } from "@/config";
+import axios from "axios";
+
+
+export default function GitHubRepoCard() {
+ const [isOpen, setIsOpen] = useState(false);
+
+
+ const handleGithubClick = async () => {
+ try {
+
+ const githubToken = localStorage.getItem("githubToken");
+ const githubUsername = localStorage.getItem("githubUsername");
+
+ if (!githubToken) {
+ return (window.location.href = `${BACKEND_URL}/auth/github`);
+ }
+ const response = await axios.post(`${BACKEND_URL}/createrepo`,
+ {
+ githubToken,
+ githubUsername,
+ files: [
+ {
+ name: "myFile.txt",
+ content: "This is the content of my file."
+ },
+ {
+ name: "anotherFile.js",
+ content: "console.log('Hello from another file!');"
+ }
+ ]
+ },
+ );
+
+ if (response.data.repoUrl) {
+ window.open(response.data.repoUrl, "_blank");
+ }
+ } catch {
+ alert("Failed to clone repository");
+ }
+};
+
+ return (
+
+
+
+
+ {isOpen && (
+
+
GitHub
+
+ This project is connected to
+ {`mobile-magic`}.
+
Changes will be committed to the main branch.
+
+
+
+
+
+
+
+
+ )}
+
+ );
+}
\ No newline at end of file
From d2dccefb5e734349f449d58e97bb824fba1cb8c9 Mon Sep 17 00:00:00 2001
From: Shivam Ross <144504100+shivam-ross@users.noreply.github.com>
Date: Wed, 12 Mar 2025 19:43:00 +0530
Subject: [PATCH 2/7] Update Appbar.tsx
---
mobile-magic/apps/frontend/components/Appbar.tsx | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mobile-magic/apps/frontend/components/Appbar.tsx b/mobile-magic/apps/frontend/components/Appbar.tsx
index 5053343..6990b34 100644
--- a/mobile-magic/apps/frontend/components/Appbar.tsx
+++ b/mobile-magic/apps/frontend/components/Appbar.tsx
@@ -46,6 +46,9 @@ export function Appbar() {
+
+
+
);
From d2e5652ea387af2d09a72d0ebc3ad5d6223f5dc5 Mon Sep 17 00:00:00 2001
From: Shivam Ross <144504100+shivam-ross@users.noreply.github.com>
Date: Wed, 12 Mar 2025 19:44:02 +0530
Subject: [PATCH 3/7] Update Appbar.tsx
---
mobile-magic/apps/frontend/components/Appbar.tsx | 1 +
1 file changed, 1 insertion(+)
diff --git a/mobile-magic/apps/frontend/components/Appbar.tsx b/mobile-magic/apps/frontend/components/Appbar.tsx
index 6990b34..692fa04 100644
--- a/mobile-magic/apps/frontend/components/Appbar.tsx
+++ b/mobile-magic/apps/frontend/components/Appbar.tsx
@@ -11,6 +11,7 @@ import { Header } from '@/components/Header'
import { motion } from 'motion/react'
import { containerVariants, itemVariants } from '@/lib/animation-variants'
import { ThemeButton } from '@/components/theme-button'
+import GitHubRepoCard from './Githubcard'
export function Appbar() {
return (
From f679937ba30691b3b2841badd2df714064f25d72 Mon Sep 17 00:00:00 2001
From: Shivam Ross <144504100+shivam-ross@users.noreply.github.com>
Date: Wed, 12 Mar 2025 19:50:47 +0530
Subject: [PATCH 4/7] Update index.ts
---
mobile-magic/apps/primary-backend/index.ts | 92 +++++++++++++++++++++-
1 file changed, 91 insertions(+), 1 deletion(-)
diff --git a/mobile-magic/apps/primary-backend/index.ts b/mobile-magic/apps/primary-backend/index.ts
index 554ac18..43f4ce7 100644
--- a/mobile-magic/apps/primary-backend/index.ts
+++ b/mobile-magic/apps/primary-backend/index.ts
@@ -2,8 +2,12 @@ import { prismaClient } from "db/client";
import express from "express";
import cors from "cors";
import { authMiddleware } from "common/middleware";
+import axios from 'axios';
const app = express();
+const CLIENT_ID = process.env.GITHUB_CLIENT_ID;
+const CLIENT_SECRET = process.env.GITHUB_CLIENT_SECRET;
+const BACKEND_URL = process.env.BACKEND_URL || "http://localhost:9090";
app.use(express.json());
app.use(cors());
@@ -40,6 +44,92 @@ app.get("/prompts/:projectId", authMiddleware, async (req, res) => {
res.json({ prompts });
});
+app.post("/createrepo", async (req, res) => {
+ const { githubToken, githubUsername, files } = req.body;
+
+ if (!githubToken || !githubUsername) {
+ res.status(400).json({ error: "Missing parameters: githubToken and githubUsername are required." });
+ return;
+ }
+
+ if (!files || !Array.isArray(files) || files.length === 0) {
+ res.status(400).json({ error: "Missing or empty 'files' array." });
+ return;
+ }
+
+ try {
+ const newRepoName = `from-magic-mobile-${Date.now()}`;
+
+ const createRepoRes = await axios.post(
+ "https://api.github.com/user/repos",
+ { name: newRepoName, private: false },
+ { headers: { Authorization: `Bearer ${githubToken}` } }
+ );
+
+ const newRepoUrl = createRepoRes.data.html_url;
+
+ for (const file of files) {
+ if (file && file.name && file.content) {
+ const encodedContent = Buffer.from(file.content).toString("base64");
+ console.log(`Uploading ${file.name} from system to ${newRepoName}`);
+
+ await axios.put(
+ `https://api.github.com/repos/${githubUsername}/${newRepoName}/contents/${file.name}`,
+ {
+ message: `Added ${file.name} from system`,
+ content: encodedContent,
+ branch: "main",
+ },
+ { headers: { Authorization: `Bearer ${githubToken}` } }
+ );
+ } else {
+ console.warn("Invalid file object in 'files' array.");
+ }
+ }
+
+ res.status(200).json({ message: "Repository created successfully!", repoUrl: newRepoUrl });
+ } catch (error) {
+ console.error("Error creating repository:", error.response?.data || error.message);
+ res.status(500).json({ error: "Failed to create repository" });
+ }
+});
+
+app.get("/auth/github", (req, res) => {
+ const githubAuthUrl = `https://github.com/login/oauth/authorize?client_id=${CLIENT_ID}&redirect_uri=${BACKEND_URL}/auth/github/callback&scope=repo,user`;
+ res.redirect(githubAuthUrl);
+});
+
+app.get("/auth/github/callback", async (req, res) => {
+ const code = req.query.code;
+ if (!code) res.status(400).send("GitHub OAuth failed!");
+
+ try {
+
+ const tokenRes = await axios.post(
+ "https://github.com/login/oauth/access_token",
+ {
+ client_id: CLIENT_ID,
+ client_secret: CLIENT_SECRET,
+ code,
+ },
+ { headers: { Accept: "application/json" } }
+ );
+
+ const accessToken = tokenRes.data.access_token;
+
+ const userRes = await axios.get("https://api.github.com/user", {
+ headers: { Authorization: `Bearer ${accessToken}` },
+ });
+
+ const { login, id } = userRes.data;
+
+ res.redirect(`http://localhost:3000?githubToken=${accessToken}&githubId=${id}&githubUsername=${login}`); // Redirect to frontend after linking GitHub
+ } catch (error) {
+ console.error("GitHub OAuth Error:", error);
+ res.status(500).send("GitHub authentication failed");
+ }
+});
+
app.listen(9090, () => {
console.log("Server is running on port 9090");
-});
\ No newline at end of file
+});
From 179501a49e5348fd102668a27c23371b3fa2649d Mon Sep 17 00:00:00 2001
From: Shivam Ross <144504100+shivam-ross@users.noreply.github.com>
Date: Wed, 12 Mar 2025 19:55:27 +0530
Subject: [PATCH 5/7] Update .env.example
---
mobile-magic/apps/primary-backend/.env.example | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/mobile-magic/apps/primary-backend/.env.example b/mobile-magic/apps/primary-backend/.env.example
index f1c1ade..0657596 100644
--- a/mobile-magic/apps/primary-backend/.env.example
+++ b/mobile-magic/apps/primary-backend/.env.example
@@ -1 +1,3 @@
-JWT_PUBLIC_KEY=
\ No newline at end of file
+JWT_PUBLIC_KEY=
+GITHUB_CLIENT_ID=
+GITHUB_CLIENT_SECRET=
From bbb8c39918a0a92bf701e8f9a6c4d6debd7cbd03 Mon Sep 17 00:00:00 2001
From: Shivam Ross <144504100+shivam-ross@users.noreply.github.com>
Date: Wed, 12 Mar 2025 23:09:46 +0530
Subject: [PATCH 6/7] Update hero.tsx
---
mobile-magic/apps/frontend/components/hero.tsx | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/mobile-magic/apps/frontend/components/hero.tsx b/mobile-magic/apps/frontend/components/hero.tsx
index cacf4db..8f7a48c 100644
--- a/mobile-magic/apps/frontend/components/hero.tsx
+++ b/mobile-magic/apps/frontend/components/hero.tsx
@@ -4,6 +4,20 @@ import { motion } from 'motion/react'
import { containerVariants, itemVariants } from '@/lib/animation-variants'
export const Hero = () => {
+ useEffect(() => {
+ const urlParams = new URLSearchParams(window.location.search);
+ const githubToken = urlParams.get("githubToken");
+ const githubId = urlParams.get("githubId");
+ const githubUsername = urlParams.get("githubUsername");
+
+ if (githubToken && githubId && githubUsername) {
+ localStorage.setItem("githubToken", githubToken);
+ localStorage.setItem("githubId", githubId);
+ localStorage.setItem("githubUsername", githubUsername);
+ }
+ router.push("/");
+ }, [router]);
+
return (
Date: Fri, 14 Mar 2025 09:17:08 +0530
Subject: [PATCH 7/7] Update hero.tsx
---
mobile-magic/apps/frontend/components/hero.tsx | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/mobile-magic/apps/frontend/components/hero.tsx b/mobile-magic/apps/frontend/components/hero.tsx
index 8f7a48c..af2d4ed 100644
--- a/mobile-magic/apps/frontend/components/hero.tsx
+++ b/mobile-magic/apps/frontend/components/hero.tsx
@@ -2,8 +2,12 @@
import { motion } from 'motion/react'
import { containerVariants, itemVariants } from '@/lib/animation-variants'
+import { useRouter } from 'next/navigation';
+import { useEffect } from 'react';
export const Hero = () => {
+ const router = useRouter();
+
useEffect(() => {
const urlParams = new URLSearchParams(window.location.search);
const githubToken = urlParams.get("githubToken");