Skip to content

Commit

Permalink
more api stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
shie1 committed Nov 16, 2023
1 parent 3a7447d commit bbb4cea
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,30 @@ app.get("/start/:type/:id", (req, res) => {
res.send(`Started session for ${user[0]}`)
})

app.get("/users", (req, res) => {
res.json(args.users.map((user) => {
const sessionId = Object.keys(globalState).filter((key) => globalState[key].username == user[0])[0]
return {
username: user[0],
sessionId,
}
}))
})

app.get("/users/:username", (req, res) => {
const username = req.params.username
const user = args.users.filter((user) => user[0] == username)[0]
if(!user) {
res.status(404).send("User not found")
return
}
const session = Object.values(globalState).filter((state) => state.username == username)[0]
res.json({
username,
session,
})
})

app.get("/stop/:id", (req, res) => {
const id = req.params.id
if (globalState[id]) {
Expand All @@ -197,6 +221,13 @@ app.get("/stop/:id", (req, res) => {
}
})

app.get("/stopall", (req, res) => {
Object.keys(globalState).forEach((key) => {
delete globalState[key]
})
res.send("All sessions stopped")
})

app.listen(args.port, () => {
console.log(`Listening on port ${args.port}`)
})

0 comments on commit bbb4cea

Please sign in to comment.