Updated list of commands to v4.3. Added groups & permissions. Added connections. Updated redemptions and actions to v4.3.

This commit is contained in:
Tom
2024-08-14 20:33:40 +00:00
parent 6548ce33e0
commit b92529d8c0
51 changed files with 3910 additions and 799 deletions

View File

@ -15,22 +15,22 @@ export async function GET(req: Request) {
// Verify state against user id in user table.
const user = await db.user.findFirst({
where: {
id: state
}
where: {
id: state
}
})
if (!user) {
return new NextResponse("Bad Request", { status: 400 });
return new NextResponse("Bad Request", { status: 400 });
}
// Post to https://id.twitch.tv/oauth2/token
const token: { access_token:string, expires_in:number, refresh_token:string, token_type:string, scope:string[] } = (await axios.post("https://id.twitch.tv/oauth2/token", {
const token: { access_token: string, expires_in: number, refresh_token: string, token_type: string, scope: string[] } = (await axios.post("https://id.twitch.tv/oauth2/token", {
client_id: process.env.TWITCH_BOT_CLIENT_ID,
client_secret: process.env.TWITCH_BOT_CLIENT_SECRET,
code: code,
grant_type: "authorization_code",
redirect_uri: "https://hermes.goblincaves.com/api/account/authorize"
redirect_uri: "https://tomtospeech.com/api/account/authorize"
})).data
// Fetch values from token.
@ -49,17 +49,17 @@ export async function GET(req: Request) {
const broadcasterId = info.data.data[0]['id']
await db.twitchConnection.create({
data: {
broadcasterId: broadcasterId,
accessToken: access_token,
refreshToken: refresh_token,
userId: state
}
data: {
broadcasterId: broadcasterId,
accessToken: access_token,
refreshToken: refresh_token,
userId: state
}
})
return new NextResponse("", { status: 200 });
} catch (error) {
console.log("[ACCOUNT]", error);
console.log("[ACCOUNT/AUTHORIZE]", error);
return new NextResponse("Internal Error", { status: 500 });
}
}

View File

@ -39,7 +39,8 @@ export async function GET(req: Request) {
user_id: user.id,
access_token: data?.accessToken,
refresh_token: data?.refreshToken,
broadcaster_id: connection.broadcasterId
broadcaster_id: connection.broadcasterId,
expires_in
}
return NextResponse.json(dataFormatted, { status: 201 });
}
@ -75,7 +76,8 @@ export async function GET(req: Request) {
user_id: user.id,
access_token,
refresh_token,
broadcaster_id: connection.broadcasterId
broadcaster_id: connection.broadcasterId,
expires_in
}
return NextResponse.json(data)

View File

@ -18,16 +18,21 @@ export async function GET(req: Request) {
if (!auth)
return new NextResponse("Bad Request", { status: 400 })
const redemptions = await axios.get("https://api.twitch.tv/helix/channel_points/custom_rewards?broadcaster_id=" + auth.broadcaster_id,
{
headers: {
"Client-Id": process.env.TWITCH_BOT_CLIENT_ID,
"Authorization": "Bearer " + auth.access_token
try {
const redemptions = await axios.get("https://api.twitch.tv/helix/channel_points/custom_rewards?broadcaster_id=" + auth.broadcaster_id,
{
headers: {
"Client-Id": process.env.TWITCH_BOT_CLIENT_ID,
"Authorization": "Bearer " + auth.access_token
}
}
}
)
)
return NextResponse.json(redemptions.data);
return NextResponse.json(redemptions.data);
} catch (error: any) {
console.error('Fetching Twitch channel redemptions:', error.response.data)
}
return NextResponse.json([]);
} catch (error) {
console.log("[REDEMPTIONS/ACTIONS]", error);
return new NextResponse("Internal Error", { status: 500 });

View File

@ -6,9 +6,16 @@ import fetchUser from "@/lib/fetch-user";
export async function GET(req: Request) {
try {
const user = await fetchUser(req)
if (!user) return new NextResponse("Internal Error", { status: 401 })
return NextResponse.json(user)
const user = await fetchUser(req)
if (!user) return new NextResponse("Internal Error", { status: 401 })
const account = await db.account.findFirst({
where: {
userId: user.id
}
});
return NextResponse.json({ ... user, broadcasterId: account?.providerAccountId })
} catch (error) {
console.log("[ACCOUNT]", error);
return new NextResponse("Internal Error", { status: 500 });
@ -22,29 +29,29 @@ export async function POST(req: Request) {
if (!user) {
return new NextResponse("Internal Error", { status: 401 })
}
const exist = await db.user.findFirst({
where: {
name: user
}
where: {
name: user
}
});
if (exist) {
return NextResponse.json({
id: exist.id,
username: exist.name
id: exist.id,
username: exist.name
});
}
const newUser = await db.user.create({
data: {
name: user,
}
data: {
name: user,
}
});
return NextResponse.json({
id: newUser.id,
username: newUser.name
id: newUser.id,
username: newUser.name
});
} catch (error) {
console.log("[ACCOUNT]", error);