Add API function for getting a user's configuration.
parent
c745572a7e
commit
db8d9dfe72
35
docs/REST.md
35
docs/REST.md
|
@ -51,22 +51,24 @@ play from: rtmp://example.com/live/username or https://example.com/live/username
|
||||||
|
|
||||||
### /api/users/live/
|
### /api/users/live/
|
||||||
|
|
||||||
|
UNFINISHED
|
||||||
|
|
||||||
Returns the usernames and stream titles of 10 users who are currently streaming
|
Returns the usernames and stream titles of 10 users who are currently streaming
|
||||||
|
|
||||||
Method: GET
|
Method: GET
|
||||||
|
|
||||||
Authentication: no
|
Authentication: no
|
||||||
|
|
||||||
Parameters: none
|
Parameters: num (optional), sort (optional)
|
||||||
|
|
||||||
Response: Returns an array of objects containing the username and title of each stream. Returns an empty array if no one is streaming.
|
Response: Returns an array of objects containing the username and title of each stream. Returns an empty array if no one is streaming.
|
||||||
|
|
||||||
Example: `[{username:"foo", title:"bar"}]`
|
Example: `[{username:"foo", title:"bar"}]`
|
||||||
|
|
||||||
|
|
||||||
### /api/users/live/:num
|
### /api/users/all
|
||||||
|
|
||||||
Same as above, with number indicated the number of users to list. Maximum of 50.
|
Same as above, but returns all users regardless of whether they are streaming. Also unfinished.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,7 +142,7 @@ Method: POST
|
||||||
|
|
||||||
Authentication: yes
|
Authentication: yes
|
||||||
|
|
||||||
Paramters: A string array of the names of vods to be deleted.
|
Paramters: A string array of the names of vods to be deleted. (Do not include the file extension);
|
||||||
|
|
||||||
Response: Returns `{error: "error code"}` or `{success: ""}`
|
Response: Returns `{error: "error code"}` or `{success: ""}`
|
||||||
|
|
||||||
|
@ -170,7 +172,7 @@ Parameters: A valid JWT cookie. No other parameters.
|
||||||
|
|
||||||
Response: Returns `{error: "error code"}` or `{success: "new_stream_key"}`
|
Response: Returns `{error: "error code"}` or `{success: "new_stream_key"}`
|
||||||
|
|
||||||
### /api/:user/vods/list
|
### /api/:user/vods
|
||||||
|
|
||||||
Get a list of the named users VODs
|
Get a list of the named users VODs
|
||||||
|
|
||||||
|
@ -178,7 +180,7 @@ Method: GET
|
||||||
|
|
||||||
Authentication: no
|
Authentication: no
|
||||||
|
|
||||||
Parameters: none
|
Parameters: user
|
||||||
|
|
||||||
Response: Returns an array of VODs with the format `[{"name":"yote.mp4"},{"name":"yeet.mp4"}]`
|
Response: Returns an array of VODs with the format `[{"name":"yote.mp4"},{"name":"yeet.mp4"}]`
|
||||||
|
|
||||||
|
@ -186,17 +188,22 @@ Notes: VODs are always available at http://domain.com/publicEndpoint/username/fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## /api/:user/config
|
||||||
|
|
||||||
|
Method: GET
|
||||||
|
|
||||||
|
Authentication: optional
|
||||||
|
|
||||||
|
Parameters: user
|
||||||
|
|
||||||
|
Response: Returns a JSON object with available information about the user. If the user is authenticated and searching for their own information, will return all available information. Otherwise it will return only the stream title and bio. In the case of searching for a user that does not exist, the returned object will contain only the username searched for.
|
||||||
|
|
||||||
|
Example: `{username: "foo", title: "bar", about: "This is an example bio"}`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Not Yet Implemented
|
## Not Yet Implemented
|
||||||
|
|
||||||
#### /api/:user/info
|
|
||||||
|
|
||||||
List bio, stream title. If authenticated, list all settings.
|
|
||||||
|
|
||||||
#### /api/user/streamkey/current
|
#### /api/user/streamkey/current
|
||||||
|
|
||||||
Return current stream key
|
Return current stream key
|
||||||
|
|
||||||
#### /api/users/live
|
|
||||||
|
|
||||||
Paging and sorting coming Soon(tm)
|
|
19
src/api.ts
19
src/api.ts
|
@ -69,4 +69,21 @@ async function deleteVODs(vodlist: Array<string>, username: string): Promise<obj
|
||||||
return {"success":""};
|
return {"success":""};
|
||||||
}
|
}
|
||||||
|
|
||||||
export { register, update, changepwd, changesk, login, updateChat, deleteVODs };
|
async function getConfig(username: string, all?: boolean): Promise<object>{
|
||||||
|
let t = {username: username};
|
||||||
|
if(all) {
|
||||||
|
let users = await db.query('SELECT stream_key,record_flag FROM users WHERE username='+db.raw.escape(username));
|
||||||
|
if(users[0]) Object.assign(t, users[0]);
|
||||||
|
let usermeta = await db.query('SELECT title,about FROM user_meta WHERE username='+db.raw.escape(username));
|
||||||
|
if(usermeta[0]) Object.assign(t, users[0]);
|
||||||
|
let ci = await db.query('SELECT irc,xmpp,twitch,discord FROM chat_integration WHERE username='+db.raw.escape(username));
|
||||||
|
if(ci[0]) Object.assign(t, ci[0]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let um = await db.query('SELECT title,about FROM user_meta WHERE username='+db.raw.escape(username));
|
||||||
|
if(um[0]) Object.assign(t, um[0]);
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { register, update, changepwd, changesk, login, updateChat, deleteVODs, getConfig };
|
37
src/http.ts
37
src/http.ts
|
@ -168,15 +168,23 @@ async function initAPI() {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
app.get('/api/users/live', (req, res) => {
|
app.get('/api/users/live', (req, res) => {
|
||||||
|
if(req.params.sort) {
|
||||||
|
|
||||||
|
}
|
||||||
|
if(req.params.num){
|
||||||
|
|
||||||
|
}
|
||||||
db.query('select username,title from user_meta where live=1 limit 10;').then((result) => {
|
db.query('select username,title from user_meta where live=1 limit 10;').then((result) => {
|
||||||
res.send(result);
|
res.send(result);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
app.get('/api/users/live/:num', (req, res) => {
|
app.get('/api/users/all', (req, res) => {
|
||||||
if(req.params.num > 50) req.params.num = 50;
|
if(req.params.sort) {
|
||||||
db.query('select username,title from user_meta where live=1 limit '+req.params.num+';').then((result) => {
|
|
||||||
res.send(result);
|
}
|
||||||
});
|
if(req.params.num) {
|
||||||
|
|
||||||
|
}
|
||||||
});
|
});
|
||||||
app.post('/api/register', (req, res) => {
|
app.post('/api/register', (req, res) => {
|
||||||
api.register(req.body.username, req.body.password, req.body.confirm).then( (result) => {
|
api.register(req.body.username, req.body.password, req.body.confirm).then( (result) => {
|
||||||
|
@ -312,7 +320,7 @@ async function initAPI() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
app.get('/api/:user/vods/list', (req, res) => {
|
app.get('/api/:user/vods', (req, res) => {
|
||||||
readdir('./site/live/'+req.params.user, {withFileTypes: true} , (err, files) => {
|
readdir('./site/live/'+req.params.user, {withFileTypes: true} , (err, files) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
res.send([]);
|
res.send([]);
|
||||||
|
@ -322,6 +330,23 @@ async function initAPI() {
|
||||||
res.send(list);
|
res.send(list);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
app.get('/api/:user/config', (req, res) => {
|
||||||
|
if(req.cookies.Authorization) validToken(req.cookies.Authorization).then(r => {
|
||||||
|
if(r && r['username'] === req.params.user) {
|
||||||
|
api.getConfig(req.params.user, true).then(re => {
|
||||||
|
res.send(JSON.stringify(re));
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
api.getConfig(req.params.user).then(re => {
|
||||||
|
res.send(JSON.stringify(re));
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
api.getConfig(req.params.user).then(r => {
|
||||||
|
res.send(JSON.stringify(r));
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initSite(openReg) {
|
async function initSite(openReg) {
|
||||||
|
|
Reference in New Issue