duplicate.go 813 B

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