Skip to content

armgit / my-yt

Public Imported from GitHub
0

A clean and minimal youtube frontend, without all the ads and whistles

JavaScript

unify fns rest actions

Christian Fei1fcf1cbaf1f4
diff --git a/lib/server.js b/lib/server.js
index 1ef3631..6ee16c5 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -31,13 +31,13 @@ export function createServer ({repo, connections = []}) {
/* api */
if (url.pathname === '/channels' && req.method === 'POST')
- return addChannelHandler(req, res, repo)
+ return addChannelHandler(req, res, repo, connections)
if (url.pathname === '/download-video' && req.method === 'POST')
- return downloadVideoHandler(req, res, connections)
+ return downloadVideoHandler(req, res, repo, connections)
if (url.pathname === '/summarize-video' && req.method === 'POST')
- return summarizeVideoHandler(req, res, connections)
+ return summarizeVideoHandler(req, res, repo, connections)
if (url.pathname === '/ignore-video' && req.method === 'POST')
- return ignoreVideoHandler(req, res, connections)
+ return ignoreVideoHandler(req, res, repo, connections)
if (url.pathname.match('\/videos\/.*') && req.method === 'GET')
return watchVideoHandler(req, res)
@@ -82,7 +82,7 @@ export function createServer ({repo, connections = []}) {
})
}
- async function addChannelHandler(req, res, repo) {
+ async function addChannelHandler(req, res, repo, connections = []) {
const body = await getBody(req)
let { name } = JSON.parse(body)
name = name.trim()
@@ -95,7 +95,7 @@ export function createServer ({repo, connections = []}) {
const videos = await updateAndPersistVideosForChannel(name, repo)
if (Array.isArray(videos)) {
repo.addChannel(name)
- broadcastSSE(JSON.stringify({type: 'channel', name, videos}), connections)
+ broadcastSSE(JSON.stringify({type: 'new-videos', name, videos}), connections)
res.writeHead(201, { 'Content-Type': 'text/plain' })
return res.end('Channel added')
}
@@ -104,7 +104,7 @@ export function createServer ({repo, connections = []}) {
return res.end('Channel not found')
}
- async function downloadVideoHandler(req, res, connections = []) {
+ async function downloadVideoHandler(req, res, repo, connections = []) {
const body = await getBody(req)
let { id, url } = JSON.parse(body)
@@ -133,7 +133,7 @@ export function createServer ({repo, connections = []}) {
res.end('Download started')
}
- async function summarizeVideoHandler(req, res, connections = []) {
+ async function summarizeVideoHandler(req, res, repo, connections = []) {
const body = await getBody(req)
const { id } = JSON.parse(body)
@@ -221,7 +221,7 @@ export function createServer ({repo, connections = []}) {
}
}
- async function ignoreVideoHandler(req, res) {
+ async function ignoreVideoHandler(req, res, repo, connections = []) {
const body = await getBody(req)
let { id } = JSON.parse(body)
res.writeHead(200, { 'Content-Type': 'application/json' })