-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
370 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.