Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

Commit

Permalink
Adjust to new Plex webhook form layout
Browse files Browse the repository at this point in the history
  • Loading branch information
hashworks committed May 25, 2019
1 parent cbdfdad commit d117ddc
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,16 @@ func (s server) backendHandler(c *gin.Context) {
t = time.Now()
}

// Read payload
payload, err := c.FormFile("payload")
if err != nil {
fmt.Printf("Failed to read payload: %s\n", err.Error())
c.Status(http.StatusBadRequest)
return
}

// Open payload
payloadFile, err := payload.Open()
defer payloadFile.Close()
if err != nil {
fmt.Printf("Failed to open payload: %s\n", err.Error())
jsonData, exists := c.GetPostForm("payload")
if ! exists {
fmt.Println("No payload found.")
c.Status(http.StatusBadRequest)
return
}

// Parse JSON
jsonParser := json.NewDecoder(payloadFile)
var event Event
if err := jsonParser.Decode(&event); err == nil {
if err := json.Unmarshal([]byte(jsonData), &event); err == nil {
// Begin transaction
if tx, err := s.db.Begin(); err == nil {
// Create rollback function in case shit goes downhill
Expand Down

0 comments on commit d117ddc

Please sign in to comment.