aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorAlex Pooley (@zuedev) <zuedev@gmail.com>2025-07-04 03:57:23 +0100
committerAlex Pooley (@zuedev) <zuedev@gmail.com>2025-07-04 03:57:23 +0100
commitd906faa870ee24d473f24bef153d577b9d12d884 (patch)
treefc8b3e5752762c24910b353e8c621bdbb696c49d /source
parent17a3ae2faf7ce4fb83292b1774a888053d8ea433 (diff)
downloadzue.dev-d906faa870ee24d473f24bef153d577b9d12d884.tar
zue.dev-d906faa870ee24d473f24bef153d577b9d12d884.tar.gz
zue.dev-d906faa870ee24d473f24bef153d577b9d12d884.tar.bz2
zue.dev-d906faa870ee24d473f24bef153d577b9d12d884.tar.xz
zue.dev-d906faa870ee24d473f24bef153d577b9d12d884.zip
woah, an update! 🚀
Diffstat (limited to 'source')
-rw-r--r--source/main.js99
1 files changed, 99 insertions, 0 deletions
diff --git a/source/main.js b/source/main.js
index eb1d287..7b50662 100644
--- a/source/main.js
+++ b/source/main.js
@@ -163,6 +163,105 @@ export default {
}
);
})();
+ case "/96/youtube/latest-video":
+ return (async () => {
+ const url = new URL(request.url);
+ const channel = url.searchParams.get("channel");
+
+ if (!channel)
+ return new Response(
+ JSON.stringify({
+ error: `channel not provided`,
+ }),
+ {
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ "Content-Type": "application/json",
+ },
+ }
+ );
+
+ const channelWhitelist = ["@vtsweets"];
+
+ if (!channelWhitelist.includes(channel))
+ return new Response(
+ JSON.stringify({
+ error: `channel not allowed`,
+ }),
+ {
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ "Content-Type": "application/json",
+ },
+ }
+ );
+
+ const API_Key =
+ environment.GOOGLE_API_KEY_UNRESTRICTED ||
+ (await environment.GOOGLE_API_KEY_UNRESTRICTED.get());
+
+ if (!API_Key)
+ return new Response(
+ JSON.stringify({
+ error: `API Key not found`,
+ }),
+ {
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ "Content-Type": "application/json",
+ },
+ }
+ );
+
+ const youtubeChannelsListResponse = await fetch(
+ `https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forHandle=${channel}&key=${API_Key}`
+ );
+
+ const youtubeChannelsList = await youtubeChannelsListResponse.json();
+
+ if (youtubeChannelsList.items.length === 0) {
+ return new Response(
+ JSON.stringify({
+ error: `channel not found`,
+ }),
+ {
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ "Content-Type": "application/json",
+ },
+ }
+ );
+ }
+
+ const uploadsPlaylistId =
+ youtubeChannelsList.items[0].contentDetails.relatedPlaylists
+ .uploads;
+
+ const youtubePlaylistItemsList = await fetch(
+ `https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=${uploadsPlaylistId}&maxResults=1&key=${API_Key}`
+ );
+
+ const youtubePlaylistItemsListData =
+ await youtubePlaylistItemsList.json();
+
+ if (youtubePlaylistItemsListData.items.length === 0) {
+ return new Response(
+ JSON.stringify({
+ error: `no videos found in the channel`,
+ }),
+ {
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ "Content-Type": "application/json",
+ },
+ }
+ );
+ }
+
+ return new Response(
+ youtubePlaylistItemsListData.items[0].snippet.resourceId.videoId
+ );
+ })();
case "/browser-rendering/screenshot":
return (async () => {
const { searchParams } = new URL(request.url);