Skip to content

Commit 03f9695

Browse files
committed
feat: get channels api
1 parent f8437a6 commit 03f9695

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/server.js

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export function createServer ({repo, connections = []}) {
3838
/* api */
3939
if (url.pathname === '/api/channels' && req.method === 'POST')
4040
return addChannelHandler(req, res, repo, connections)
41+
if (url.pathname === '/api/channels' && req.method === 'GET')
42+
return getChannelHandler(req, res, repo, connections)
4143
if (url.pathname === '/api/download-video' && req.method === 'POST')
4244
return downloadVideoHandler(req, res, repo, connections)
4345
if (url.pathname === '/api/summarize-video' && req.method === 'POST')
@@ -132,6 +134,12 @@ export function createServer ({repo, connections = []}) {
132134
return res.end('Channel not found')
133135
}
134136

137+
async function getChannelHandler(req, res, repo, connections = []) {
138+
const channels = repo.getChannels()
139+
res.writeHead(200, { 'Content-Type': 'application/json' })
140+
return res.end(JSON.stringify(channels))
141+
}
142+
135143
async function downloadVideoHandler(req, res, repo, connections = []) {
136144
const body = await getBody(req)
137145
let { id, external } = JSON.parse(body)

0 commit comments

Comments
 (0)