From f7c7f0578629a622473ab265c13a708ce1dd3658 Mon Sep 17 00:00:00 2001 From: knotteye Date: Thu, 30 Jul 2020 01:34:22 -0500 Subject: [PATCH] Implement an API call for getting the current stream key. --- docs/REST.md | 18 ++++++++++++++---- src/http.ts | 13 +++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/docs/REST.md b/docs/REST.md index 32087f8..4218085 100644 --- a/docs/REST.md +++ b/docs/REST.md @@ -188,7 +188,9 @@ Notes: VODs are always available at http://domain.com/publicEndpoint/username/fi -## /api/:user/config +### /api/:user/config + +Get information about the specified user. Method: GET @@ -202,8 +204,16 @@ Example: `{username: "foo", title: "bar", about: "This is an example bio"}` -## Not Yet Implemented - #### /api/user/streamkey/current -Return current stream key \ No newline at end of file +Returns current stream key for the authenticated user. + +Method: GET + +Authentication: yes + +Parameters: none + +Response: returns a JSON object with the stream key + +Example: `{"stream_key": "abcdefghijklmno12345"}` or `{"error":"error reason"}` \ No newline at end of file diff --git a/src/http.ts b/src/http.ts index 14755a2..e1e20dd 100644 --- a/src/http.ts +++ b/src/http.ts @@ -274,6 +274,19 @@ async function initAPI() { } }); }); + app.get('/api/user/streamkey/current', (req, res) => { + validToken(req.cookies.Authorization).then((t) => { + if(t) { + db.query('SELECT stream_key FROM users WHERE username='+db.raw.escape(t['username'])).then(o => { + if(o[0]) res.send(o[0]); + else res.send('{"error":""}'); + }); + } + else { + res.send('{"error":"invalid token"}'); + } + }); + }); app.post('/api/user/streamkey', (req, res) => { validToken(req.cookies.Authorization).then((t) => { if(t) {