Skip to content

armgit / my-yt

Public Imported from GitHub
0

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

JavaScript

feat: get channels api

Christian Fei03f9695a6419
diff --git a/lib/server.js b/lib/server.js
index 2851731..ddb1790 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -38,6 +38,8 @@ export function createServer ({repo, connections = []}) {
/* api */
if (url.pathname === '/api/channels' && req.method === 'POST')
return addChannelHandler(req, res, repo, connections)
+ if (url.pathname === '/api/channels' && req.method === 'GET')
+ return getChannelHandler(req, res, repo, connections)
if (url.pathname === '/api/download-video' && req.method === 'POST')
return downloadVideoHandler(req, res, repo, connections)
if (url.pathname === '/api/summarize-video' && req.method === 'POST')
@@ -132,6 +134,12 @@ export function createServer ({repo, connections = []}) {
return res.end('Channel not found')
}
+ async function getChannelHandler(req, res, repo, connections = []) {
+ const channels = repo.getChannels()
+ res.writeHead(200, { 'Content-Type': 'application/json' })
+ return res.end(JSON.stringify(channels))
+ }
+
async function downloadVideoHandler(req, res, repo, connections = []) {
const body = await getBody(req)
let { id, external } = JSON.parse(body)