mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
50 lines
1.3 KiB
JavaScript
Executable File
50 lines
1.3 KiB
JavaScript
Executable File
import { StreamingProfile } from "@db_models"
|
|
import NewStreamingProfile from "@services/newStreamingProfile"
|
|
import composeStreamingSources from "@utils/compose-streaming-sources"
|
|
|
|
export default {
|
|
method: "GET",
|
|
route: "/streaming/profiles",
|
|
middlewares: ["withAuthentication"],
|
|
fn: async (req, res) => {
|
|
const user_id = req.user._id.toString()
|
|
|
|
if (!user_id) {
|
|
return res.status(400).json({
|
|
error: "Invalid request, missing user_id"
|
|
})
|
|
}
|
|
|
|
let profiles = await StreamingProfile.find({
|
|
user_id,
|
|
}).select("+stream_key")
|
|
|
|
if (profiles.length === 0) {
|
|
// create a new profile
|
|
const profile = await NewStreamingProfile({
|
|
user_id,
|
|
profile_name: "default",
|
|
})
|
|
|
|
profiles = [profile]
|
|
}
|
|
|
|
profiles = profiles.map((profile) => {
|
|
profile = profile.toObject()
|
|
|
|
profile._id = profile._id.toString()
|
|
|
|
profile.stream_key = `${req.user.username}__${profile._id}?secret=${profile.stream_key}`
|
|
|
|
return profile
|
|
})
|
|
|
|
profiles = profiles.map((profile) => {
|
|
profile.addresses = composeStreamingSources(req.user.username, profile._id)
|
|
|
|
return profile
|
|
})
|
|
|
|
return res.json(profiles)
|
|
}
|
|
} |