A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
refactor: api prefix in routes
Christian Feie7d8df30141b
diff --git a/client/components/add-channel-form.js b/client/components/add-channel-form.jsindex 9008053..3be959b 100644--- a/client/components/add-channel-form.js+++ b/client/components/add-channel-form.js@@ -39,7 +39,7 @@ class AddChannelForm extends HTMLElement {freezeForm()- fetch('/channels', {+ fetch('/api/channels', {method: 'POST',headers: { 'Content-Type': 'application/json' },body: JSON.stringify({ name: channelName })diff --git a/client/components/video-element.js b/client/components/video-element.jsindex 8a4c4cc..66263a3 100644--- a/client/components/video-element.js+++ b/client/components/video-element.js@@ -116,7 +116,7 @@ class VideoElement extends HTMLElement {const downloadStartedText = '⚡️ Download started'if (event.target.innerText === downloadStartedText) return console.log('already downloading')event.target.innerText = downloadStartedText- fetch('/download-video', {+ fetch('/api/download-video', {method: 'POST',headers: { 'Content-Type': 'application/json' },body: JSON.stringify({ id: this.video.id }),@@ -129,7 +129,7 @@ class VideoElement extends HTMLElement {const summaryStartedText = '⚡️ summary started'if (event.target.innerText === summaryStartedText) return console.log('already summarizing')event.target.innerText = summaryStartedText- fetch('/summarize-video', {+ fetch('/api/summarize-video', {method: 'POST',headers: { 'Content-Type': 'application/json' },body: JSON.stringify({ id: this.video.id }),@@ -154,7 +154,7 @@ class VideoElement extends HTMLElement {toggleIgnoreVideoHandler (event) {event.preventDefault()- fetch('/ignore-video', {+ fetch('/api/ignore-video', {method: 'POST',headers: { 'Content-Type': 'application/json' },body: JSON.stringify({ id: this.video.id }),diff --git a/client/lib/router.js b/client/lib/router.jsindex e7d5b7b..dd40b21 100644--- a/client/lib/router.js+++ b/client/lib/router.js@@ -16,7 +16,7 @@ const routes = {let $videosContainer = document.querySelector('.main-videos-container')if (!$videosContainer) return- let videos = await fetch('/videos').then(res => res.json())+ let videos = await fetch('/api/videos').then(res => res.json())console.log('videos.length', videos.length)if (videos.length === 0) {document.querySelector('empty-state').style.display = ''diff --git a/lib/server.js b/lib/server.jsindex 1eafd13..7759191 100644--- a/lib/server.js+++ b/lib/server.js@@ -36,19 +36,19 @@ export function createServer ({repo, connections = []}) {if (req.headers.accept && req.headers.accept.indexOf('text/event-stream') >= 0) return handleSSE(res, connections)/* api */- if (url.pathname === '/channels' && req.method === 'POST')+ if (url.pathname === '/api/channels' && req.method === 'POST')return addChannelHandler(req, res, repo, connections)- if (url.pathname === '/download-video' && req.method === 'POST')+ if (url.pathname === '/api/download-video' && req.method === 'POST')return downloadVideoHandler(req, res, repo, connections)- if (url.pathname === '/summarize-video' && req.method === 'POST')+ if (url.pathname === '/api/summarize-video' && req.method === 'POST')return summarizeVideoHandler(req, res, repo, connections, llmSettings)- if (url.pathname === '/ignore-video' && req.method === 'POST')+ if (url.pathname === '/api/ignore-video' && req.method === 'POST')return ignoreVideoHandler(req, res, repo, connections)- if (url.pathname === '/videos' && req.method === 'GET')+ if (url.pathname === '/api/videos' && req.method === 'GET')return allVideosHandler(req, res, repo, connections)- if (url.pathname.match('\/videos\/.*') && req.method === 'GET')+ if (url.pathname.match(/\/videos\/.*/) && req.method === 'GET')return watchVideoHandler(req, res)- if (url.pathname.match('\/captions\/.*') && req.method === 'GET')+ if (url.pathname.match(/\/captions\/.*/) && req.method === 'GET')return captionsHandler(req, res)/* client */@@ -227,6 +227,7 @@ export function createServer ({repo, connections = []}) {res.writeHead(200, { 'Content-Type': 'application/json' })res.end(JSON.stringify(videos))}+function captionsHandler(req, res) {// return vtt file of videoconst captionsPath = './data' + req.url.replace('captions', 'videos') + '.en.vtt'