youtuber-blog/src/routes/channels.js

32 lines
713 B
JavaScript
Raw Normal View History

2024-04-21 22:41:38 +00:00
/** @typedef {import("fastify").FastifyInstance} FastifyInstance */
import { authMiddleware } from "../modules/middleware.js";
2024-04-24 20:49:59 +00:00
import { getAccessToken, getChannelInfo } from "../utils/youtube.js";
2024-04-21 22:41:38 +00:00
/**
*
* @param {FastifyInstance} fastify
* @param {unknown} _
* @param {() => void} done
*/
export const channelRoutes = (fastify, _, done) => {
fastify.register(authMiddleware);
fastify.get("/", async (request, response) => {
try {
2024-04-24 20:49:59 +00:00
const access_token = await getAccessToken(fastify, request);
2024-04-21 22:41:38 +00:00
2024-04-24 20:49:59 +00:00
const channel = await getChannelInfo(access_token);
2024-04-21 22:41:38 +00:00
response.send({
success: true,
channel
})
} catch (e) {
console.log(e);
}
});
done();
};