refactor: refactor app and api

This commit is contained in:
0xJacky 2023-11-29 00:08:44 +08:00
parent 5ab50b8a93
commit 287ef7527d
No known key found for this signature in database
GPG key ID: B6E4A6E4A561BAF0
157 changed files with 8116 additions and 3587 deletions

44
api/sites/duplicate.go Normal file
View file

@ -0,0 +1,44 @@
package sites
import (
"github.com/0xJacky/Nginx-UI/api"
"github.com/0xJacky/Nginx-UI/internal/helper"
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/gin-gonic/gin"
"net/http"
)
func DuplicateSite(c *gin.Context) {
// Source name
name := c.Param("name")
// Destination name
var json struct {
Name string `json:"name" binding:"required"`
}
if !api.BindAndValid(c, &json) {
return
}
src := nginx.GetConfPath("sites-available", name)
dst := nginx.GetConfPath("sites-available", json.Name)
if helper.FileExists(dst) {
c.JSON(http.StatusNotAcceptable, gin.H{
"message": "File exists",
})
return
}
_, err := helper.CopyFile(src, dst)
if err != nil {
api.ErrHandler(c, err)
return
}
c.JSON(http.StatusOK, gin.H{
"dst": dst,
})
}