From b0b00014d5b58345acdf0fc59994d32489ad9689 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Wed, 25 Nov 2020 13:34:08 +1300 Subject: [PATCH] Proxy thumbnails in cloudtube --- api/thumbnails.js | 18 ++++++++++++++++++ pug/includes/video-list-item.pug | 3 +-- 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 api/thumbnails.js diff --git a/api/thumbnails.js b/api/thumbnails.js new file mode 100644 index 0000000..e8b6cb4 --- /dev/null +++ b/api/thumbnails.js @@ -0,0 +1,18 @@ +const fetch = require("node-fetch") +const constants = require("../utils/constants.js") + +module.exports = [ + { + route: `/vi/(${constants.regex.video_id})/(\\w+\\.jpg)`, methods: ["GET"], code: ({fill}) => { + const videoID = fill[0] + const file = fill[1] + return fetch(`https://i.ytimg.com/vi/${videoID}/${file}`).then(res => { + return { + statusCode: 200, + contentType: "image/jpeg", + stream: res.body + } + }) + } + } +] diff --git a/pug/includes/video-list-item.pug b/pug/includes/video-list-item.pug index 7883a20..58e5f31 100644 --- a/pug/includes/video-list-item.pug +++ b/pug/includes/video-list-item.pug @@ -1,8 +1,7 @@ mixin video_list_item(video, instanceOrigin) - - if (!instanceOrigin) instanceOrigin = "https://i.ytimg.com" - let link = `/watch?v=${video.videoId}` a(href=link tabindex="-1").thumbnail - img(src=`${instanceOrigin}/vi/${video.videoId}/mqdefault.jpg` width=320 height=180 alt="").image + img(src=`/vi/${video.videoId}/mqdefault.jpg` width=320 height=180 alt="").image if video.second__lengthText != undefined span.duration= video.second__lengthText .info