Implement an API call for getting the current stream key.

merge-requests/15/head
knotteye 4 years ago
parent df51432a8f
commit f7c7f05786
  1. 18
      docs/REST.md
  2. 13
      src/http.ts

@ -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
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"}`

@ -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) {