-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kostya Bats
committed
Oct 25, 2024
1 parent
f07ec0e
commit 93fa85f
Showing
4 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package signalling | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
"log" | ||
"path" | ||
"strings" | ||
) | ||
|
||
func (s *Server) setupAgentApi() { | ||
s.app.Route("/api/agent", func(router fiber.Router) { | ||
router.Post("/:peerName/record_upload", func(c *fiber.Ctx) error { | ||
if s.config.RecordStorageDir == "" { | ||
return c.Status(fiber.StatusMethodNotAllowed).SendString("Record storage is not enabled") | ||
} | ||
|
||
peerName := c.Params("peerName") | ||
|
||
file, err := c.FormFile("file") | ||
if err != nil { | ||
return c.Status(fiber.StatusBadRequest).SendString("No file to upload") | ||
} | ||
if !strings.HasSuffix(file.Filename, ".webm") { | ||
return c.Status(fiber.StatusBadRequest).SendString("File has incorrect extension") | ||
} | ||
|
||
log.Printf("Store agent record file %s (%dKB)", file.Filename, file.Size/1024) | ||
|
||
destination := path.Join(s.config.RecordStorageDir, peerName+"_"+file.Filename) | ||
if err := c.SaveFile(file, destination); err != nil { | ||
return c.Status(fiber.StatusBadRequest).SendString("Failed to upload file") | ||
} | ||
|
||
return nil | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters