pubsubhubbub test
This commit is contained in:
parent
7f72636af2
commit
23ce45e16f
@ -25,5 +25,39 @@ export const webhookRoutes = (fastify, _, done) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
fastify.get("/youtube", async (req, reply) => {
|
||||||
|
// Check if the request contains the 'hub.challenge' query parameter
|
||||||
|
if (request.query.hub.challenge) {
|
||||||
|
// Respond with the challenge to verify the subscription
|
||||||
|
return reply.send(request.query.hub.challenge);
|
||||||
|
} else {
|
||||||
|
// Handle other cases or errors
|
||||||
|
return reply.code(404).send("Not found");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
fastify.post("/youtube", async (req, reply) => {
|
||||||
|
const { headers, payload } = request;
|
||||||
|
const contentType = headers['content-type'];
|
||||||
|
|
||||||
|
// Check if the content type is 'application/atom+xml'
|
||||||
|
if (contentType === 'application/atom+xml') {
|
||||||
|
// Parse the XML payload
|
||||||
|
const { entries } = payload;
|
||||||
|
|
||||||
|
// Example processing: log the video IDs of new videos
|
||||||
|
entries.forEach(entry => {
|
||||||
|
const videoId = entry.find('yt:videoId').value;
|
||||||
|
console.log(`New video uploaded: ${videoId}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Respond with a success status
|
||||||
|
return reply.code(200).send();
|
||||||
|
} else {
|
||||||
|
// Respond with an error status if the content type is not expected
|
||||||
|
return reply.code(400).send("Bad Request");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user