mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-11 03:24:16 +00:00
implement handleInfoUpdate
method
This commit is contained in:
parent
e2d4eba699
commit
b308eda05d
@ -1,9 +1,10 @@
|
|||||||
import { Controller } from "linebridge/dist/server"
|
import { Controller } from "linebridge/dist/server"
|
||||||
import { User, StreamingKey } from "../../models"
|
|
||||||
import { nanoid } from "nanoid"
|
import { nanoid } from "nanoid"
|
||||||
import lodash from "lodash"
|
import lodash from "lodash"
|
||||||
import axios from "axios"
|
import axios from "axios"
|
||||||
|
|
||||||
|
import { User, StreamingKey, StreamingInfo } from "../../models"
|
||||||
|
|
||||||
const streamingIngestServer = process.env.STREAMING_INGEST_SERVER
|
const streamingIngestServer = process.env.STREAMING_INGEST_SERVER
|
||||||
const streamingServerAPIAddress = process.env.STREAMING_API_SERVER
|
const streamingServerAPIAddress = process.env.STREAMING_API_SERVER
|
||||||
const streamingServerAPIProtocol = streamingServerAPIAddress.startsWith("https") ? "https" : "http"
|
const streamingServerAPIProtocol = streamingServerAPIAddress.startsWith("https") ? "https" : "http"
|
||||||
@ -104,6 +105,42 @@ export default class StreamingController extends Controller {
|
|||||||
this.streamings = this.streamings.filter((streaming) => streaming.stream !== stream)
|
this.streamings = this.streamings.filter((streaming) => streaming.stream !== stream)
|
||||||
|
|
||||||
return streaming
|
return streaming
|
||||||
|
},
|
||||||
|
handleInfoUpdate: async (payload) => {
|
||||||
|
let info = await StreamingInfo.findOne({
|
||||||
|
user_id: payload.user_id
|
||||||
|
}).catch((err) => {
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
|
const payloadValues = {
|
||||||
|
title: payload.title,
|
||||||
|
description: payload.description,
|
||||||
|
category: payload.category,
|
||||||
|
thumbnail: payload.thumbnail,
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!info) {
|
||||||
|
// create new info
|
||||||
|
info = new StreamingInfo({
|
||||||
|
user_id: payload.user_id,
|
||||||
|
...payloadValues
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// merge data
|
||||||
|
info = lodash.merge(info, {
|
||||||
|
title: payload.title,
|
||||||
|
description: payload.description,
|
||||||
|
category: payload.category,
|
||||||
|
thumbnail: payload.thumbnail,
|
||||||
|
})
|
||||||
|
|
||||||
|
await info.save()
|
||||||
|
|
||||||
|
global.wsInterface.io.emit(`streaming.info_update.${payload.user_id}`, info)
|
||||||
|
|
||||||
|
return info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,6 +216,31 @@ export default class StreamingController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
post = {
|
post = {
|
||||||
|
"/streaming/update_info": {
|
||||||
|
middlewares: ["withAuthentication"],
|
||||||
|
fn: async (req, res) => {
|
||||||
|
const { title, description, category, thumbnail } = req.body
|
||||||
|
|
||||||
|
const info = await this.methods.handleInfoUpdate({
|
||||||
|
user_id: req.user._id.toString(),
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
category,
|
||||||
|
thumbnail
|
||||||
|
}).catch((err) => {
|
||||||
|
console.error(err)
|
||||||
|
|
||||||
|
res.status(500).json({
|
||||||
|
error: `Cannot update info: ${err.message}`,
|
||||||
|
})
|
||||||
|
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
|
if (info) {
|
||||||
|
return res.json(info)
|
||||||
|
}
|
||||||
|
},
|
||||||
"/streaming/publish": async (req, res) => {
|
"/streaming/publish": async (req, res) => {
|
||||||
const { app, stream, tcUrl } = req.body
|
const { app, stream, tcUrl } = req.body
|
||||||
|
|
||||||
@ -262,4 +324,5 @@ export default class StreamingController extends Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user