37 lines
904 B
JavaScript
37 lines
904 B
JavaScript
|
/** @typedef {import("fastify").FastifyInstance} FastifyInstance */
|
||
|
|
||
|
import { authMiddleware } from "../modules/middleware.js";
|
||
|
import { 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 {
|
||
|
console.log(request.session);
|
||
|
|
||
|
const { token } = await fastify.googleOAuth2.getNewAccessTokenUsingRefreshToken({
|
||
|
refresh_token: request.session.google_refresh_token,
|
||
|
expires_at: request.session.expires_at
|
||
|
});
|
||
|
console.log(token);
|
||
|
const channel = await getChannelInfo(token.access_token);
|
||
|
|
||
|
response.send({
|
||
|
success: true,
|
||
|
channel
|
||
|
})
|
||
|
} catch (e) {
|
||
|
console.log(e);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
done();
|
||
|
};
|