1
0

duplicate.go 781 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package sites
  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. "net/http"
  8. )
  9. func DuplicateSite(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 !api.BindAndValid(c, &json) {
  17. return
  18. }
  19. src := nginx.GetConfPath("sites-available", name)
  20. dst := nginx.GetConfPath("sites-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. api.ErrHandler(c, err)
  30. return
  31. }
  32. c.JSON(http.StatusOK, gin.H{
  33. "dst": dst,
  34. })
  35. }