youtuber-blog/src/routes/channels.js
2024-04-24 22:49:59 +02:00

32 lines
713 B
JavaScript

/** @typedef {import("fastify").FastifyInstance} FastifyInstance */
import { authMiddleware } from "../modules/middleware.js";
import { getAccessToken, getChannelInfo } from "../utils/youtube.js";
/**
*
* @param {FastifyInstance} fastify
* @param {unknown} _
* @param {() => void} done
*/
export const channelRoutes = (fastify, _, done) => {
fastify.register(authMiddleware);
fastify.get("/", async (request, response) => {
try {
const access_token = await getAccessToken(fastify, request);
const channel = await getChannelInfo(access_token);
response.send({
success: true,
channel
})
} catch (e) {
console.log(e);
}
});
done();
};