A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
refactor: videos and captions handler under /api
Christian Feie1b9dedafd4b
diff --git a/client/components/video-element.js b/client/components/video-element.jsindex fd09f1e..a551f82 100644--- a/client/components/video-element.js+++ b/client/components/video-element.js@@ -91,11 +91,11 @@ class VideoElement extends HTMLElement {event.preventDefault()this.querySelector('.play.video-placeholder').outerHTML = /*html*/`<video controls playsinline style="user-select: none; width: 400px; width: -webkit-fill-available;">- <source src="/videos/${this.video.id}.${this.video.format || 'mp4'}" type="video/${this.video.format || 'mp4'}" />- <track default kind="captions" srclang="en" src="/captions/${this.video.id}" />+ <source src="/api/videos/${this.video.id}.${this.video.format || 'mp4'}" type="video/${this.video.format || 'mp4'}" />+ <track default kind="captions" srclang="en" src="/api/captions/${this.video.id}" /><p>Your browser does not support the video tag.- Download the video instead <a href="/videos/${this.video.id}" target="_blank">here</a>+ Download the video instead <a href="/api/videos/${this.video.id}" target="_blank">here</a></p></video>`diff --git a/lib/server.js b/lib/server.jsindex bc6f580..5e5c1de 100644--- a/lib/server.js+++ b/lib/server.js@@ -63,9 +63,9 @@ export function createServer ({repo, state = {}, connections = [], updateVideosreturn diskUsageHandler(req, res, repo, connections)if (url.pathname === '/api/reclaim-disk-space' && req.method === 'POST')return reclaimDiskSpaceHandler(req, res, repo, connections)- if (url.pathname.match(/\/videos\/.*/) && req.method === 'GET')+ if (url.pathname.match(/\/api\/videos\/.*/) && req.method === 'GET')return watchVideoHandler(req, res, repo)- if (url.pathname.match(/\/captions\/.*/) && req.method === 'GET')+ if (url.pathname.match(/\/api\/captions\/.*/) && req.method === 'GET')return captionsHandler(req, res, repo)/* client */@@ -234,7 +234,7 @@ async function deleteVideoHandler(req, res, repo, connections = []) {}function watchVideoHandler(req, res, repo) {- const id = req.url.replace('/videos/', '').replace(/\.(webm|mp4)$/, '')+ const id = req.url.replace('/api/videos/', '').replace(/\.(webm|mp4)$/, '')const video = repo.getVideo(id)const location = video.location || `./data/videos/${id}.mp4`const contentType = video.format ? `video/${video.format}` : "video/mp4"@@ -380,7 +380,7 @@ async function reclaimDiskSpaceHandler(req, res, repo) {}function captionsHandler(req, res) {- const captionsPath = './data' + req.url.replace('captions', 'videos') + '.en.vtt'+ const captionsPath = './data' + req.url.replace('api/captions', 'videos') + '.en.vtt'if (!fs.existsSync(captionsPath)) {res.writeHead(404)res.end()