Compare commits

..

2 commits

Author SHA1 Message Date
41b97a053a
Merge 3cc2dd758a into 6678ded2f9 2024-08-25 20:20:13 +00:00
3cc2dd758a
feat: return channels 2024-08-25 22:20:11 +02:00
2 changed files with 24 additions and 5 deletions

View file

@ -14,6 +14,20 @@ export async function getGuild(
return guild; 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<Guild[]> { export async function getUserGuilds(user): Promise<Guild[]> {
const discordApiGuildsResponse = await fetch( const discordApiGuildsResponse = await fetch(
"https://discord.com/api/v10/users/@me/guilds", "https://discord.com/api/v10/users/@me/guilds",

View file

@ -1,7 +1,11 @@
import type { APIRoute } from "astro"; import type { APIContext, APIRoute } from "astro";
import { filterUserGuilds, getUserGuilds } from "~/lib/guilds"; 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; const user = locals.user;
if (!user) { if (!user) {
return new Response(null, { return new Response(null, {
@ -9,6 +13,7 @@ export const GET: APIRoute = async ({ locals }) => {
}); });
} }
console.log(user); const channels = await getGuildChannels(params.id!, locals.runtime.env);
return Response.json([]);
return Response.json(channels);
}; };