Skip to content

Commit

Permalink
Added transcode
Browse files Browse the repository at this point in the history
  • Loading branch information
hkirat committed Aug 30, 2024
1 parent 0966fa1 commit 1565ed6
Show file tree
Hide file tree
Showing 13 changed files with 370 additions and 280 deletions.
3 changes: 3 additions & 0 deletions prisma/migrations/20240830204152_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "VideoMetadata" ADD COLUMN "original_mp4_url" TEXT,
ADD COLUMN "transcoded" BOOLEAN NOT NULL DEFAULT false;
2 changes: 2 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ model VideoMetadata {
migrated_video_1080p_mp4_1 String?
migrated_video_360p_mp4_1 String?
migrated_video_720p_mp4_1 String?
original_mp4_url String?
transcoded Boolean @default(false)
@@unique([contentId])
}
Expand Down
129 changes: 70 additions & 59 deletions src/app/api/github/callback/route.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,82 @@
import prisma from "@/db";
import { authOptions } from "@/lib/auth";
import { getServerSession } from "next-auth";
import { NextRequest, NextResponse } from "next/server";
import prisma from '@/db';
import { authOptions } from '@/lib/auth';
import { getServerSession } from 'next-auth';
import { NextRequest, NextResponse } from 'next/server';

export async function GET(req: NextRequest) {
const code = req.nextUrl.searchParams.get('code');
const code = req.nextUrl.searchParams.get('code');

const session = await getServerSession(authOptions);
const session = await getServerSession(authOptions);

if (!session?.user?.id || !code) {
return NextResponse.redirect(new URL('/payout-methods?error=invalid_session', req.url));
}

try {
// Exchange code for access token
const tokenResponse = await fetch('https://github.com/login/oauth/access_token', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify({
client_id: process.env.GITHUB_ID,
client_secret: process.env.GITHUB_SECRET,
code,
}),
});
if (!session?.user?.id || !code) {
return NextResponse.redirect(
new URL('/payout-methods?error=invalid_session', req.url),
);
}

const tokenData = await tokenResponse.json();
console.log('Token data:', tokenData);
try {
// Exchange code for access token
const tokenResponse = await fetch(
'https://github.com/login/oauth/access_token',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify({
client_id: process.env.GITHUB_ID,
client_secret: process.env.GITHUB_SECRET,
code,
}),
},
);

if (tokenData.error) {
throw new Error(tokenData.error_description);
}
const tokenData = await tokenResponse.json();
console.log('Token data:', tokenData);

// Get user info from GitHub
const userResponse = await fetch('https://api.github.com/user', {
headers: {
Authorization: `token ${tokenData.access_token}`,
},
});
if (tokenData.error) {
throw new Error(tokenData.error_description);
}

const userData = await userResponse.json();
console.log('User data:', userData);
// Get user info from GitHub
const userResponse = await fetch('https://api.github.com/user', {
headers: {
Authorization: `token ${tokenData.access_token}`,
},
});

const existingLink = await prisma.gitHubLink.findUnique({
where: { userId: session.user.id },
});
const userData = await userResponse.json();
console.log('User data:', userData);

if (!existingLink) {
await prisma.gitHubLink.create({
data: {
userId: session.user.id,
githubId: userData.id.toString(),
username: userData.login,
access_token: tokenData.access_token,
avatarUrl: userData.avatar_url,
profileUrl: userData.html_url,
},
});
} else {
return NextResponse.redirect(new URL('/payout-methods?github_linked=true', req.url));
}
const existingLink = await prisma.gitHubLink.findUnique({
where: { userId: session.user.id },
});

return NextResponse.redirect(new URL('/payout-methods?github_linked=true', req.url));
} catch (error) {
console.error('Error linking GitHub:', error);
return NextResponse.redirect(new URL('/payout-methods?error=github_link_failed', req.url));
if (!existingLink) {
await prisma.gitHubLink.create({
data: {
userId: session.user.id,
githubId: userData.id.toString(),
username: userData.login,
access_token: tokenData.access_token,
avatarUrl: userData.avatar_url,
profileUrl: userData.html_url,
},
});
} else {
return NextResponse.redirect(
new URL('/payout-methods?github_linked=true', req.url),
);
}
}

return NextResponse.redirect(
new URL('/payout-methods?github_linked=true', req.url),
);
} catch (error) {
console.error('Error linking GitHub:', error);
return NextResponse.redirect(
new URL('/payout-methods?error=github_link_failed', req.url),
);
}
}
102 changes: 61 additions & 41 deletions src/app/api/github/details/route.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,68 @@
import prisma from "@/db";
import { authOptions } from "@/lib/auth";
import { getServerSession } from "next-auth";
import { NextResponse } from "next/server";
import prisma from '@/db';
import { authOptions } from '@/lib/auth';
import { getServerSession } from 'next-auth';
import { NextResponse } from 'next/server';

export async function GET() {
const session = await getServerSession(authOptions);

if (!session) {
return NextResponse.json({ message: 'Unauthorised', success: 'false' }, { status: 401 });
}

const githubData = await prisma.gitHubLink.findMany({
where: {
userId: session?.user?.id
},
select: {
avatarUrl: true,
username: true,
profileUrl: true,
}
});
const session = await getServerSession(authOptions);

if (!session) {
return NextResponse.json(
{ message: 'Unauthorised', success: 'false' },
{ status: 401 },
);
}

if (!githubData) {
return NextResponse.json({ message: "Couldn't find any Linked github", success: 'false' });
}
const githubData = await prisma.gitHubLink.findMany({
where: {
userId: session?.user?.id,
},
select: {
avatarUrl: true,
username: true,
profileUrl: true,
},
});

return NextResponse.json({ message: "found data successsfully", data: githubData, success: 'true' });
if (!githubData) {
return NextResponse.json({
message: "Couldn't find any Linked github",
success: 'false',
});
}

return NextResponse.json({
message: 'found data successsfully',
data: githubData,
success: 'true',
});
}

export async function DELETE() {
const session = await getServerSession(authOptions);

if (!session) {
return NextResponse.json({ message: 'Unauthorised', success: 'false' }, { status: 401 });
}

try {
await prisma.gitHubLink.delete({
where: {
userId: session?.user?.id
},
});
return NextResponse.json({ message: "Github unlinked succeessfully", success: 'true' });
} catch (error) {
return NextResponse.json({ message: "Something went wrong", error: error, success: 'false' });
}
}
const session = await getServerSession(authOptions);

if (!session) {
return NextResponse.json(
{ message: 'Unauthorised', success: 'false' },
{ status: 401 },
);
}

try {
await prisma.gitHubLink.delete({
where: {
userId: session?.user?.id,
},
});
return NextResponse.json({
message: 'Github unlinked succeessfully',
success: 'true',
});
} catch (error) {
return NextResponse.json({
message: 'Something went wrong',
error,
success: 'false',
});
}
}
14 changes: 7 additions & 7 deletions src/app/api/github/link/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { NextResponse } from "next/server";
import { NextResponse } from 'next/server';

export async function GET() {
const clientId = process.env.GITHUB_ID;
const redirectUri = `${process.env.NEXTAUTH_URL}/api/github/callback`;
const scope = 'read:user user:email';
const clientId = process.env.GITHUB_ID;
const redirectUri = `${process.env.NEXTAUTH_URL}/api/github/callback`;
const scope = 'read:user user:email';

const githubAuthUrl = `https://github.com/login/oauth/authorize?client_id=${clientId}&redirect_uri=${redirectUri}&scope=${scope}`;
const githubAuthUrl = `https://github.com/login/oauth/authorize?client_id=${clientId}&redirect_uri=${redirectUri}&scope=${scope}`;

return NextResponse.redirect(githubAuthUrl);
}
return NextResponse.redirect(githubAuthUrl);
}
30 changes: 18 additions & 12 deletions src/app/payout-methods/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@
import { useEffect, useState } from 'react';
import NewPayoutDialog from '@/components/NewPayoutDialog';
import { GitHubLinkButton } from '@/components/GitHubLinkButton';
import SOL from "../../../public/platform/sol.svg"
import UPI from "../../../public/platform/upi.svg"
import SOL from '../../../public/platform/sol.svg';
import UPI from '../../../public/platform/upi.svg';
import { PayoutMethodCard } from '@/components/PaymentMethodCard';
import { usePayoutMethods } from '@/hooks/usePayoutMethod';

export default function Page() {
const [isDialogBoxOpen, setIsDialogBoxOpen] = useState<boolean>(false);
const [btnClicked, setBtnClicked] = useState<string>('');
const { upiAddresses, solanaAddresses, handleUpiDelete, handleSolanaDelete, fetchPayoutMethods } = usePayoutMethods();
const {
upiAddresses,
solanaAddresses,
handleUpiDelete,
handleSolanaDelete,
fetchPayoutMethods,
} = usePayoutMethods();

const openDialog = (method: string) => {
setIsDialogBoxOpen(true);
Expand All @@ -19,18 +25,20 @@ export default function Page() {

useEffect(() => {
fetchPayoutMethods();
}, [isDialogBoxOpen])
}, [isDialogBoxOpen]);

const closeDialog = () => setIsDialogBoxOpen(false);

return (
<div className="h-max pb-4 transition-colors duration-500 md:p-8">
<div className="mb-6 flex flex-col items-start justify-center px-4 pt-3 sm:px-8">
<div className="text-3xl text-black my-2 mb-6 transition-colors duration-500 dark:text-white">
<h1 className="text-black dark:text-white font-semibold">Payout Methods</h1>
<div className="my-2 mb-6 text-3xl text-black transition-colors duration-500 dark:text-white">
<h1 className="font-semibold text-black dark:text-white">
Payout Methods
</h1>
</div>

<div className='grid grid-cols-1 sm:grid-cols-2 w-full md:grid-cols-3 gap-4'>
<div className="grid w-full grid-cols-1 gap-4 sm:grid-cols-2 md:grid-cols-3">
<PayoutMethodCard
title="UPI Address"
description="Add your UPI ID"
Expand All @@ -57,14 +65,12 @@ export default function Page() {
title={btnClicked}
/>

<div className='w-full my-8'>
<h2 className='text-3xl my-4 font-semibold'>Apps</h2>
<div className='grid grid-cols-1 sm:grid-cols-2 w-full md:grid-cols-3 gap-4'>
<div className="my-8 w-full">
<h2 className="my-4 text-3xl font-semibold">Apps</h2>
<div className="grid w-full grid-cols-1 gap-4 sm:grid-cols-2 md:grid-cols-3">
<GitHubLinkButton />
</div>

</div>

</div>
</div>
);
Expand Down
Loading

0 comments on commit 1565ed6

Please sign in to comment.