From 3cc2dd758aef11a6e0a114935c8ba28ccd3a72c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Sun, 25 Aug 2024 22:20:11 +0200 Subject: [PATCH] feat: return channels --- apps/website/src/lib/guilds.ts | 14 ++++++++++++++ apps/website/src/pages/api/guild/[id]/channels.ts | 15 ++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/apps/website/src/lib/guilds.ts b/apps/website/src/lib/guilds.ts index 502c7da..4375021 100644 --- a/apps/website/src/lib/guilds.ts +++ b/apps/website/src/lib/guilds.ts @@ -14,6 +14,20 @@ export async function getGuild( return guild; } +export async function getGuildChannels(guildId: string, env) { + const discordApiGuildChannelsResponse = await fetch( + `https://discord.com/api/v10/guilds/${guildId}/channels`, + { + headers: { + Authorization: `Bot ${env.DISCORD_BOT_TOKEN}`, + "Cache-Control": "max-age=300", + }, + } + ); + + return await discordApiGuildChannelsResponse.json(); +} + export async function getUserGuilds(user): Promise { const discordApiGuildsResponse = await fetch( "https://discord.com/api/v10/users/@me/guilds", diff --git a/apps/website/src/pages/api/guild/[id]/channels.ts b/apps/website/src/pages/api/guild/[id]/channels.ts index 828ed55..c241ddf 100644 --- a/apps/website/src/pages/api/guild/[id]/channels.ts +++ b/apps/website/src/pages/api/guild/[id]/channels.ts @@ -1,7 +1,11 @@ -import type { APIRoute } from "astro"; -import { filterUserGuilds, getUserGuilds } from "~/lib/guilds"; +import type { APIContext, APIRoute } from "astro"; +import { getGuildChannels } from "~/lib/guilds"; -export const GET: APIRoute = async ({ locals }) => { +interface APIParams { + id: string; +} + +export const GET: APIRoute = async ({ params, locals }) => { const user = locals.user; if (!user) { return new Response(null, { @@ -9,6 +13,7 @@ export const GET: APIRoute = async ({ locals }) => { }); } - console.log(user); - return Response.json([]); + const channels = await getGuildChannels(params.id!, locals.runtime.env); + + return Response.json(channels); };