Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl: for post request #413

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 78 additions & 14 deletions pkg/controllers/bbb_api_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,49 @@ func HandleVerifyApiRequest(c *fiber.Ctx) error {
return c.XML(bbbapiwrapper.CommonResponseMsg("FAILED", "apiKeyError", "invalid api key"))
}

q := c.Queries()
if (q == nil || len(q) == 0) || (strings.HasSuffix(c.Path(), "/api") || strings.HasSuffix(c.Path(), "/api/")) {
hasParams := false
var data, method, rType string
if c.Method() == "GET" {
if len(c.Queries()) > 0 {
rType = "get"
hasParams = true
}
} else if c.Method() == "POST" {
if c.Get("Content-Type") == "application/x-www-form-urlencoded" {
if len(c.Body()) > 0 {
hasParams = true
rType = "post"
}
} else {
// probably xml for Pre-upload Slides
if len(c.Queries()) > 0 {
hasParams = true
rType = "get"
}
}
} else {
return c.XML(bbbapiwrapper.CommonResponseMsg("FAILED", "error", "unsupported http method"))
}

if !hasParams || (strings.HasSuffix(c.Path(), "/api") || strings.HasSuffix(c.Path(), "/api/")) {
return c.XML(bbbapiwrapper.CommonApiVersion{
ReturnCode: "SUCCESS",
Version: 0.9,
})
}

s1 := strings.Split(c.OriginalURL(), "?")
// we'll get method
s2 := strings.Split(s1[0], "/")
method := s2[len(s2)-1]
if rType == "post" {
s2 := strings.Split(c.Path(), "/")
method = s2[len(s2)-1]
data = string(c.Body())
} else {
s1 := strings.Split(c.OriginalURL(), "?")
s2 := strings.Split(c.Path(), "/")
method = s2[len(s2)-1]
data = s1[1]
}

s3 := strings.Split(s1[1], "checksum=")
s3 := strings.Split(data, "checksum=")
if len(s3) < 1 {
return c.XML(bbbapiwrapper.CommonResponseMsg("FAILED", "checksumError", "Checksums do not match"))
}
Expand All @@ -59,7 +88,12 @@ func HandleVerifyApiRequest(c *fiber.Ctx) error {

func HandleBBBCreate(c *fiber.Ctx) error {
q := new(bbbapiwrapper.CreateMeetingReq)
err := c.QueryParser(q)
var err error = nil
if c.Method() == "POST" && c.Get("Content-Type") == "application/x-www-form-urlencoded" {
err = c.BodyParser(q)
} else {
err = c.QueryParser(q)
}
if err != nil {
return c.XML(bbbapiwrapper.CommonResponseMsg("FAILED", "parsingError", "We can not parse request"))
}
Expand Down Expand Up @@ -100,7 +134,12 @@ func HandleBBBCreate(c *fiber.Ctx) error {

func HandleBBBJoin(c *fiber.Ctx) error {
q := new(bbbapiwrapper.JoinMeetingReq)
err := c.QueryParser(q)
var err error = nil
if c.Method() == "POST" && c.Get("Content-Type") == "application/x-www-form-urlencoded" {
err = c.BodyParser(q)
} else {
err = c.QueryParser(q)
}
if err != nil {
return c.XML(bbbapiwrapper.CommonResponseMsg("FAILED", "parsingError", "We can not parse request"))
}
Expand Down Expand Up @@ -184,7 +223,12 @@ func HandleBBBJoin(c *fiber.Ctx) error {

func HandleBBBIsMeetingRunning(c *fiber.Ctx) error {
q := new(bbbapiwrapper.MeetingReq)
err := c.QueryParser(q)
var err error = nil
if c.Method() == "POST" && c.Get("Content-Type") == "application/x-www-form-urlencoded" {
err = c.BodyParser(q)
} else {
err = c.QueryParser(q)
}
if err != nil {
return c.XML(bbbapiwrapper.CommonResponseMsg("FAILED", "parsingError", "We can not parse request"))
}
Expand All @@ -202,7 +246,12 @@ func HandleBBBIsMeetingRunning(c *fiber.Ctx) error {

func HandleBBBGetMeetingInfo(c *fiber.Ctx) error {
q := new(bbbapiwrapper.MeetingReq)
err := c.QueryParser(q)
var err error = nil
if c.Method() == "POST" && c.Get("Content-Type") == "application/x-www-form-urlencoded" {
err = c.BodyParser(q)
} else {
err = c.QueryParser(q)
}
if err != nil {
return c.XML(bbbapiwrapper.CommonResponseMsg("FAILED", "parsingError", "We can not parse request"))
}
Expand Down Expand Up @@ -252,7 +301,12 @@ func HandleBBBGetMeetings(c *fiber.Ctx) error {

func HandleBBBEndMeetings(c *fiber.Ctx) error {
q := new(bbbapiwrapper.MeetingReq)
err := c.QueryParser(q)
var err error = nil
if c.Method() == "POST" && c.Get("Content-Type") == "application/x-www-form-urlencoded" {
err = c.BodyParser(q)
} else {
err = c.QueryParser(q)
}
if err != nil {
return c.XML(bbbapiwrapper.CommonResponseMsg("FAILED", "parsingError", "We can not parse request"))
}
Expand All @@ -270,7 +324,12 @@ func HandleBBBEndMeetings(c *fiber.Ctx) error {

func HandleBBBGetRecordings(c *fiber.Ctx) error {
q := new(bbbapiwrapper.GetRecordingsReq)
err := c.QueryParser(q)
var err error = nil
if c.Method() == "POST" && c.Get("Content-Type") == "application/x-www-form-urlencoded" {
err = c.BodyParser(q)
} else {
err = c.QueryParser(q)
}
if err != nil {
return c.XML(bbbapiwrapper.CommonResponseMsg("FAILED", "parsingError", "We can not parse request"))
}
Expand All @@ -295,7 +354,12 @@ func HandleBBBGetRecordings(c *fiber.Ctx) error {

func HandleBBBDeleteRecordings(c *fiber.Ctx) error {
q := new(bbbapiwrapper.DeleteRecordingsReq)
err := c.QueryParser(q)
var err error = nil
if c.Method() == "POST" && c.Get("Content-Type") == "application/x-www-form-urlencoded" {
err = c.BodyParser(q)
} else {
err = c.QueryParser(q)
}
if err != nil {
return c.XML(bbbapiwrapper.CommonResponseMsg("FAILED", "parsingError", "We can not parse request"))
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/handler/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,16 @@ func Router() *fiber.App {
// for convert BBB request to PlugNmeet
bbb := app.Group("/:apiKey/bigbluebutton/api", controllers.HandleVerifyApiRequest)
bbb.All("/create", controllers.HandleBBBCreate)
bbb.Get("/join", controllers.HandleBBBJoin)
bbb.Get("/isMeetingRunning", controllers.HandleBBBIsMeetingRunning)
bbb.Get("/getMeetingInfo", controllers.HandleBBBGetMeetingInfo)
bbb.Get("/getMeetings", controllers.HandleBBBGetMeetings)
bbb.Get("/end", controllers.HandleBBBEndMeetings)
bbb.Get("/getRecordings", controllers.HandleBBBGetRecordings)
bbb.Get("/deleteRecordings", controllers.HandleBBBDeleteRecordings)
bbb.All("/join", controllers.HandleBBBJoin)
bbb.All("/isMeetingRunning", controllers.HandleBBBIsMeetingRunning)
bbb.All("/getMeetingInfo", controllers.HandleBBBGetMeetingInfo)
bbb.All("/getMeetings", controllers.HandleBBBGetMeetings)
bbb.All("/end", controllers.HandleBBBEndMeetings)
bbb.All("/getRecordings", controllers.HandleBBBGetRecordings)
bbb.All("/deleteRecordings", controllers.HandleBBBDeleteRecordings)
// TO-DO: in the future
bbb.Get("/updateRecordings", controllers.HandleBBBUpdateRecordings)
bbb.Get("/publishRecordings", controllers.HandleBBBPublishRecordings)
bbb.All("/updateRecordings", controllers.HandleBBBUpdateRecordings)
bbb.All("/publishRecordings", controllers.HandleBBBPublishRecordings)

// api group will require sending token as Authorization header value
api := app.Group("/api", controllers.HandleVerifyHeaderToken)
Expand Down
Loading