duplicate.go 780 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package streams
  2. import (
  3. "net/http"
  4. "github.com/0xJacky/Nginx-UI/internal/helper"
  5. "github.com/0xJacky/Nginx-UI/internal/nginx"
  6. "github.com/gin-gonic/gin"
  7. "github.com/uozi-tech/cosy"
  8. )
  9. func Duplicate(c *gin.Context) {
  10. // Source name
  11. name := c.Param("name")
  12. // Destination name
  13. var json struct {
  14. Name string `json:"name" binding:"required"`
  15. }
  16. if !cosy.BindAndValid(c, &json) {
  17. return
  18. }
  19. src := nginx.GetConfPath("streams-available", name)
  20. dst := nginx.GetConfPath("streams-available", json.Name)
  21. if helper.FileExists(dst) {
  22. c.JSON(http.StatusNotAcceptable, gin.H{
  23. "message": "File exists",
  24. })
  25. return
  26. }
  27. _, err := helper.CopyFile(src, dst)
  28. if err != nil {
  29. cosy.ErrHandler(c, err)
  30. return
  31. }
  32. c.JSON(http.StatusOK, gin.H{
  33. "dst": dst,
  34. })
  35. }