diff --git a/app/http/controllers/website_controller.go b/app/http/controllers/website_controller.go index 70895731..509c2c25 100644 --- a/app/http/controllers/website_controller.go +++ b/app/http/controllers/website_controller.go @@ -39,7 +39,7 @@ func NewWebsiteController() *WebsiteController { // @Security BearerToken // @Param data body commonrequests.Paginate true "request" // @Success 200 {object} SuccessResponse{data=responses.List} -// @Router /panel/website [get] +// @Router /panel/websites [get] func (r *WebsiteController) List(ctx http.Context) http.Response { var paginateRequest commonrequests.Paginate sanitize := Sanitize(ctx, &paginateRequest) @@ -71,7 +71,7 @@ func (r *WebsiteController) List(ctx http.Context) http.Response { // @Security BearerToken // @Param data body requests.Add true "request" // @Success 200 {object} SuccessResponse -// @Router /panel/website [post] +// @Router /panel/websites [post] func (r *WebsiteController) Add(ctx http.Context) http.Response { check := Check(ctx, "openresty") if check != nil { @@ -123,7 +123,7 @@ func (r *WebsiteController) Add(ctx http.Context) http.Response { // @Security BearerToken // @Param id path int true "网站 ID" // @Success 200 {object} SuccessResponse -// @Router /panel/website/{id} [delete] +// @Router /panel/websites/{id} [delete] func (r *WebsiteController) Delete(ctx http.Context) http.Response { check := Check(ctx, "openresty") if check != nil { @@ -223,7 +223,7 @@ func (r *WebsiteController) SaveDefaultConfig(ctx http.Context) http.Response { // @Security BearerToken // @Param id path int true "网站 ID" // @Success 200 {object} SuccessResponse{data=services.PanelWebsite} -// @Router /panel/website/config/{id} [get] +// @Router /panel/websites/{id}/config [get] func (r *WebsiteController) GetConfig(ctx http.Context) http.Response { check := Check(ctx, "openresty") if check != nil { @@ -259,7 +259,7 @@ func (r *WebsiteController) GetConfig(ctx http.Context) http.Response { // @Param id path int true "网站 ID" // @Param data body requests.SaveConfig true "request" // @Success 200 {object} SuccessResponse -// @Router /panel/website/config/{id} [post] +// @Router /panel/websites/{id}/config [post] func (r *WebsiteController) SaveConfig(ctx http.Context) http.Response { check := Check(ctx, "openresty") if check != nil { @@ -293,7 +293,7 @@ func (r *WebsiteController) SaveConfig(ctx http.Context) http.Response { // @Security BearerToken // @Param id path int true "网站 ID" // @Success 200 {object} SuccessResponse -// @Router /panel/website/log/{id} [delete] +// @Router /panel/websites/{id}/log [delete] func (r *WebsiteController) ClearLog(ctx http.Context) http.Response { check := Check(ctx, "openresty") if check != nil { @@ -329,7 +329,7 @@ func (r *WebsiteController) ClearLog(ctx http.Context) http.Response { // @Security BearerToken // @Param id path int true "网站 ID" // @Success 200 {object} SuccessResponse -// @Router /panel/website/updateRemark/{id} [post] +// @Router /panel/websites/{id}/updateRemark [post] func (r *WebsiteController) UpdateRemark(ctx http.Context) http.Response { var idRequest requests.ID sanitize := Sanitize(ctx, &idRequest) @@ -384,9 +384,9 @@ func (r *WebsiteController) BackupList(ctx http.Context) http.Response { // @Accept json // @Produce json // @Security BearerToken -// @Param data body requests.ID true "request" -// @Success 200 {object} SuccessResponse -// @Router /panel/website/createBackup [post] +// @Param id path int true "网站 ID" +// @Success 200 {object} SuccessResponse +// @Router /panel/websites/{id}/createBackup [post] func (r *WebsiteController) CreateBackup(ctx http.Context) http.Response { var idRequest requests.ID sanitize := Sanitize(ctx, &idRequest) @@ -458,9 +458,9 @@ func (r *WebsiteController) UploadBackup(ctx http.Context) http.Response { // @Accept json // @Produce json // @Security BearerToken -// @Param data body requests.RestoreBackup true "request" -// @Success 200 {object} SuccessResponse -// @Router /panel/website/restoreBackup [post] +// @Param id path int true "网站 ID" +// @Success 200 {object} SuccessResponse +// @Router /panel/websites/{id}/restoreBackup [post] func (r *WebsiteController) RestoreBackup(ctx http.Context) http.Response { var restoreBackupRequest requests.RestoreBackup sanitize := Sanitize(ctx, &restoreBackupRequest) @@ -525,9 +525,9 @@ func (r *WebsiteController) DeleteBackup(ctx http.Context) http.Response { // @Accept json // @Produce json // @Security BearerToken -// @Param data body requests.ID true "request" -// @Success 200 {object} SuccessResponse -// @Router /panel/website/resetConfig [post] +// @Param id path int true "网站 ID" +// @Success 200 {object} SuccessResponse +// @Router /panel/websites/{id}/resetConfig [post] func (r *WebsiteController) ResetConfig(ctx http.Context) http.Response { check := Check(ctx, "openresty") if check != nil { @@ -636,7 +636,7 @@ server // @Security BearerToken // @Param id path int true "网站 ID" // @Success 200 {object} SuccessResponse -// @Router /panel/website/status/{id} [post] +// @Router /panel/websites/{id}/status [post] func (r *WebsiteController) Status(ctx http.Context) http.Response { check := Check(ctx, "openresty") if check != nil { diff --git a/app/http/requests/website/add.go b/app/http/requests/website/add.go index a7c679b1..bee3207b 100644 --- a/app/http/requests/website/add.go +++ b/app/http/requests/website/add.go @@ -30,7 +30,7 @@ func (r *Add) Rules(ctx http.Context) map[string]string { "path": "regex:^/[a-zA-Z0-9_-]+(\\/[a-zA-Z0-9_-]+)*$", "php": "required", "db": "bool", - "db_type": "required_if:db,true|in:mysql,postgresql", + "db_type": "required_if:db,true|in:0,mysql,postgresql", "db_name": "required_if:db,true|regex:^[a-zA-Z0-9_-]+$", "db_user": "required_if:db,true|regex:^[a-zA-Z0-9_-]+$", "db_password": "required_if:db,true|min_len:8", diff --git a/app/http/requests/website/save_config.go b/app/http/requests/website/save_config.go index e33e8a4a..dee0f5e7 100644 --- a/app/http/requests/website/save_config.go +++ b/app/http/requests/website/save_config.go @@ -22,7 +22,7 @@ type SaveConfig struct { Root string `form:"root" json:"root"` Raw string `form:"raw" json:"raw"` Rewrite string `form:"rewrite" json:"rewrite"` - Php int `form:"php" json:"php" filter:"uint"` + Php int `form:"php" json:"php" filter:"int"` SslCertificate string `form:"ssl_certificate" json:"ssl_certificate"` SslCertificateKey string `form:"ssl_certificate_key" json:"ssl_certificate_key"` } @@ -36,11 +36,11 @@ func (r *SaveConfig) Rules(ctx http.Context) map[string]string { "id": "required|exists:websites,id", "domains": "required|slice", "ports": "required|slice", - "hsts": "required|bool", - "ssl": "required|bool", - "http_redirect": "required|bool", - "open_basedir": "required|bool", - "waf": "required|bool", + "hsts": "bool", + "ssl": "bool", + "http_redirect": "bool", + "open_basedir": "bool", + "waf": "bool", "waf_cache": "required|string", "waf_mode": "required|string", "waf_cc_deny": "required|string", @@ -49,9 +49,9 @@ func (r *SaveConfig) Rules(ctx http.Context) map[string]string { "root": "required|string", "raw": "required|string", "rewrite": "string", - "php": "required|uint", - "ssl_certificate": "required_if:ssl,true", - "ssl_certificate_key": "required_if:ssl,true", + "php": "int", + "ssl_certificate": "required_if:ssl,true|bool", + "ssl_certificate_key": "required_if:ssl,true|bool", } } diff --git a/app/services/website.go b/app/services/website.go index e1dc10c6..45b0febb 100644 --- a/app/services/website.go +++ b/app/services/website.go @@ -50,7 +50,7 @@ type WebsiteSetting struct { Root string `json:"root"` Path string `json:"path"` Index string `json:"index"` - Php string `json:"php"` + Php int `json:"php"` OpenBasedir bool `json:"open_basedir"` Ssl bool `json:"ssl"` SslCertificate string `json:"ssl_certificate"` @@ -572,7 +572,7 @@ func (r *WebsiteImpl) GetConfig(id uint) (WebsiteSetting, error) { setting.Name = website.Name setting.Path = website.Path setting.Ssl = website.Ssl - setting.Php = strconv.Itoa(website.Php) + setting.Php = website.Php setting.Raw = config ports := tools.Cut(config, "# port标记位开始", "# port标记位结束") diff --git a/docs/docs.go b/docs/docs.go index d8e5d92f..cbb2f04b 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1017,91 +1017,6 @@ const docTemplate = `{ } } }, - "/panel/website": { - "get": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "获取网站管理的网站列表", - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "获取网站列表", - "parameters": [ - { - "description": "request", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/commonrequests.Paginate" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "allOf": [ - { - "$ref": "#/definitions/controllers.SuccessResponse" - }, - { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/responses.List" - } - } - } - ] - } - } - } - }, - "post": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "添加网站到网站管理", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "添加网站", - "parameters": [ - { - "description": "request", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.Add" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controllers.SuccessResponse" - } - } - } - } - }, "/panel/website/backupList": { "get": { "security": [ @@ -1142,138 +1057,6 @@ const docTemplate = `{ } } }, - "/panel/website/config/{id}": { - "get": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "获取网站的配置", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "获取配置", - "parameters": [ - { - "type": "integer", - "description": "网站 ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "allOf": [ - { - "$ref": "#/definitions/controllers.SuccessResponse" - }, - { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/services.PanelWebsite" - } - } - } - ] - } - } - } - }, - "post": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "保存网站的配置", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "保存配置", - "parameters": [ - { - "type": "integer", - "description": "网站 ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "request", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.SaveConfig" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controllers.SuccessResponse" - } - } - } - } - }, - "/panel/website/createBackup": { - "post": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "创建网站的备份", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "创建备份", - "parameters": [ - { - "description": "request", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.ID" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controllers.SuccessResponse" - } - } - } - } - }, "/panel/website/defaultConfig": { "get": { "security": [ @@ -1393,195 +1176,6 @@ const docTemplate = `{ } } }, - "/panel/website/log/{id}": { - "delete": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "清空网站的日志", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "清空日志", - "parameters": [ - { - "type": "integer", - "description": "网站 ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controllers.SuccessResponse" - } - } - } - } - }, - "/panel/website/resetConfig": { - "post": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "重置网站的配置", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "重置配置", - "parameters": [ - { - "description": "request", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.ID" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controllers.SuccessResponse" - } - } - } - } - }, - "/panel/website/restoreBackup": { - "post": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "还原网站的备份", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "还原备份", - "parameters": [ - { - "description": "request", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.RestoreBackup" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controllers.SuccessResponse" - } - } - } - } - }, - "/panel/website/status/{id}": { - "post": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "启用或停用网站", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "状态", - "parameters": [ - { - "type": "integer", - "description": "网站 ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controllers.SuccessResponse" - } - } - } - } - }, - "/panel/website/updateRemark/{id}": { - "post": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "更新网站的备注", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "更新备注", - "parameters": [ - { - "type": "integer", - "description": "网站 ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controllers.SuccessResponse" - } - } - } - } - }, "/panel/website/uploadBackup": { "post": { "security": [ @@ -1619,7 +1213,92 @@ const docTemplate = `{ } } }, - "/panel/website/{id}": { + "/panel/websites": { + "get": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "获取网站管理的网站列表", + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "获取网站列表", + "parameters": [ + { + "description": "request", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/commonrequests.Paginate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controllers.SuccessResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/responses.List" + } + } + } + ] + } + } + } + }, + "post": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "添加网站到网站管理", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "添加网站", + "parameters": [ + { + "description": "request", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.Add" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.SuccessResponse" + } + } + } + } + }, + "/panel/websites/{id}": { "delete": { "security": [ { @@ -1656,6 +1335,321 @@ const docTemplate = `{ } } }, + "/panel/websites/{id}/config": { + "get": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "获取网站的配置", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "获取配置", + "parameters": [ + { + "type": "integer", + "description": "网站 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controllers.SuccessResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/services.PanelWebsite" + } + } + } + ] + } + } + } + }, + "post": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "保存网站的配置", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "保存配置", + "parameters": [ + { + "type": "integer", + "description": "网站 ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "request", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.SaveConfig" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.SuccessResponse" + } + } + } + } + }, + "/panel/websites/{id}/createBackup": { + "post": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "创建网站的备份", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "创建备份", + "parameters": [ + { + "type": "integer", + "description": "网站 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.SuccessResponse" + } + } + } + } + }, + "/panel/websites/{id}/log": { + "delete": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "清空网站的日志", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "清空日志", + "parameters": [ + { + "type": "integer", + "description": "网站 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.SuccessResponse" + } + } + } + } + }, + "/panel/websites/{id}/resetConfig": { + "post": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "重置网站的配置", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "重置配置", + "parameters": [ + { + "type": "integer", + "description": "网站 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.SuccessResponse" + } + } + } + } + }, + "/panel/websites/{id}/restoreBackup": { + "post": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "还原网站的备份", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "还原备份", + "parameters": [ + { + "type": "integer", + "description": "网站 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.SuccessResponse" + } + } + } + } + }, + "/panel/websites/{id}/status": { + "post": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "启用或停用网站", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "状态", + "parameters": [ + { + "type": "integer", + "description": "网站 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.SuccessResponse" + } + } + } + } + }, + "/panel/websites/{id}/updateRemark": { + "post": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "更新网站的备注", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "更新备注", + "parameters": [ + { + "type": "integer", + "description": "网站 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.SuccessResponse" + } + } + } + } + }, "/swagger": { "get": { "description": "Swagger UI", @@ -1927,6 +1921,9 @@ const docTemplate = `{ "name": { "type": "string" }, + "path": { + "type": "string" + }, "php": { "type": "integer" }, @@ -2032,14 +2029,6 @@ const docTemplate = `{ } } }, - "requests.ID": { - "type": "object", - "properties": { - "id": { - "type": "integer" - } - } - }, "requests.Login": { "type": "object", "properties": { @@ -2067,17 +2056,6 @@ const docTemplate = `{ } } }, - "requests.RestoreBackup": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "name": { - "type": "string" - } - } - }, "requests.SaveConfig": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 48a08fee..b8e8acb8 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1010,91 +1010,6 @@ } } }, - "/panel/website": { - "get": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "获取网站管理的网站列表", - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "获取网站列表", - "parameters": [ - { - "description": "request", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/commonrequests.Paginate" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "allOf": [ - { - "$ref": "#/definitions/controllers.SuccessResponse" - }, - { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/responses.List" - } - } - } - ] - } - } - } - }, - "post": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "添加网站到网站管理", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "添加网站", - "parameters": [ - { - "description": "request", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.Add" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controllers.SuccessResponse" - } - } - } - } - }, "/panel/website/backupList": { "get": { "security": [ @@ -1135,138 +1050,6 @@ } } }, - "/panel/website/config/{id}": { - "get": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "获取网站的配置", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "获取配置", - "parameters": [ - { - "type": "integer", - "description": "网站 ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "allOf": [ - { - "$ref": "#/definitions/controllers.SuccessResponse" - }, - { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/services.PanelWebsite" - } - } - } - ] - } - } - } - }, - "post": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "保存网站的配置", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "保存配置", - "parameters": [ - { - "type": "integer", - "description": "网站 ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "request", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.SaveConfig" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controllers.SuccessResponse" - } - } - } - } - }, - "/panel/website/createBackup": { - "post": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "创建网站的备份", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "创建备份", - "parameters": [ - { - "description": "request", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.ID" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controllers.SuccessResponse" - } - } - } - } - }, "/panel/website/defaultConfig": { "get": { "security": [ @@ -1386,195 +1169,6 @@ } } }, - "/panel/website/log/{id}": { - "delete": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "清空网站的日志", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "清空日志", - "parameters": [ - { - "type": "integer", - "description": "网站 ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controllers.SuccessResponse" - } - } - } - } - }, - "/panel/website/resetConfig": { - "post": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "重置网站的配置", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "重置配置", - "parameters": [ - { - "description": "request", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.ID" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controllers.SuccessResponse" - } - } - } - } - }, - "/panel/website/restoreBackup": { - "post": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "还原网站的备份", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "还原备份", - "parameters": [ - { - "description": "request", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/requests.RestoreBackup" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controllers.SuccessResponse" - } - } - } - } - }, - "/panel/website/status/{id}": { - "post": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "启用或停用网站", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "状态", - "parameters": [ - { - "type": "integer", - "description": "网站 ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controllers.SuccessResponse" - } - } - } - } - }, - "/panel/website/updateRemark/{id}": { - "post": { - "security": [ - { - "BearerToken": [] - } - ], - "description": "更新网站的备注", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "网站管理" - ], - "summary": "更新备注", - "parameters": [ - { - "type": "integer", - "description": "网站 ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controllers.SuccessResponse" - } - } - } - } - }, "/panel/website/uploadBackup": { "post": { "security": [ @@ -1612,7 +1206,92 @@ } } }, - "/panel/website/{id}": { + "/panel/websites": { + "get": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "获取网站管理的网站列表", + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "获取网站列表", + "parameters": [ + { + "description": "request", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/commonrequests.Paginate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controllers.SuccessResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/responses.List" + } + } + } + ] + } + } + } + }, + "post": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "添加网站到网站管理", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "添加网站", + "parameters": [ + { + "description": "request", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.Add" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.SuccessResponse" + } + } + } + } + }, + "/panel/websites/{id}": { "delete": { "security": [ { @@ -1649,6 +1328,321 @@ } } }, + "/panel/websites/{id}/config": { + "get": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "获取网站的配置", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "获取配置", + "parameters": [ + { + "type": "integer", + "description": "网站 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controllers.SuccessResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/services.PanelWebsite" + } + } + } + ] + } + } + } + }, + "post": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "保存网站的配置", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "保存配置", + "parameters": [ + { + "type": "integer", + "description": "网站 ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "request", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/requests.SaveConfig" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.SuccessResponse" + } + } + } + } + }, + "/panel/websites/{id}/createBackup": { + "post": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "创建网站的备份", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "创建备份", + "parameters": [ + { + "type": "integer", + "description": "网站 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.SuccessResponse" + } + } + } + } + }, + "/panel/websites/{id}/log": { + "delete": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "清空网站的日志", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "清空日志", + "parameters": [ + { + "type": "integer", + "description": "网站 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.SuccessResponse" + } + } + } + } + }, + "/panel/websites/{id}/resetConfig": { + "post": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "重置网站的配置", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "重置配置", + "parameters": [ + { + "type": "integer", + "description": "网站 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.SuccessResponse" + } + } + } + } + }, + "/panel/websites/{id}/restoreBackup": { + "post": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "还原网站的备份", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "还原备份", + "parameters": [ + { + "type": "integer", + "description": "网站 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.SuccessResponse" + } + } + } + } + }, + "/panel/websites/{id}/status": { + "post": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "启用或停用网站", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "状态", + "parameters": [ + { + "type": "integer", + "description": "网站 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.SuccessResponse" + } + } + } + } + }, + "/panel/websites/{id}/updateRemark": { + "post": { + "security": [ + { + "BearerToken": [] + } + ], + "description": "更新网站的备注", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "网站管理" + ], + "summary": "更新备注", + "parameters": [ + { + "type": "integer", + "description": "网站 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.SuccessResponse" + } + } + } + } + }, "/swagger": { "get": { "description": "Swagger UI", @@ -1920,6 +1914,9 @@ "name": { "type": "string" }, + "path": { + "type": "string" + }, "php": { "type": "integer" }, @@ -2025,14 +2022,6 @@ } } }, - "requests.ID": { - "type": "object", - "properties": { - "id": { - "type": "integer" - } - } - }, "requests.Login": { "type": "object", "properties": { @@ -2060,17 +2049,6 @@ } } }, - "requests.RestoreBackup": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "name": { - "type": "string" - } - } - }, "requests.SaveConfig": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 0fc28639..97155b70 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -169,6 +169,8 @@ definitions: type: array name: type: string + path: + type: string php: type: integer ports: @@ -237,11 +239,6 @@ definitions: name: type: string type: object - requests.ID: - properties: - id: - type: integer - type: object requests.Login: properties: password: @@ -259,13 +256,6 @@ definitions: id: type: integer type: object - requests.RestoreBackup: - properties: - id: - type: integer - name: - type: string - type: object requests.SaveConfig: properties: domains: @@ -1063,79 +1053,6 @@ paths: summary: 登录 tags: - 用户鉴权 - /panel/website: - get: - description: 获取网站管理的网站列表 - parameters: - - description: request - in: body - name: data - required: true - schema: - $ref: '#/definitions/commonrequests.Paginate' - produces: - - application/json - responses: - "200": - description: OK - schema: - allOf: - - $ref: '#/definitions/controllers.SuccessResponse' - - properties: - data: - $ref: '#/definitions/responses.List' - type: object - security: - - BearerToken: [] - summary: 获取网站列表 - tags: - - 网站管理 - post: - consumes: - - application/json - description: 添加网站到网站管理 - parameters: - - description: request - in: body - name: data - required: true - schema: - $ref: '#/definitions/requests.Add' - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/controllers.SuccessResponse' - security: - - BearerToken: [] - summary: 添加网站 - tags: - - 网站管理 - /panel/website/{id}: - delete: - consumes: - - application/json - description: 删除网站管理的网站 - parameters: - - description: 网站 ID - in: path - name: id - required: true - type: integer - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/controllers.SuccessResponse' - security: - - BearerToken: [] - summary: 删除网站 - tags: - - 网站管理 /panel/website/backupList: get: description: 获取网站的备份列表 @@ -1158,86 +1075,6 @@ paths: summary: 获取备份列表 tags: - 网站管理 - /panel/website/config/{id}: - get: - consumes: - - application/json - description: 获取网站的配置 - parameters: - - description: 网站 ID - in: path - name: id - required: true - type: integer - produces: - - application/json - responses: - "200": - description: OK - schema: - allOf: - - $ref: '#/definitions/controllers.SuccessResponse' - - properties: - data: - $ref: '#/definitions/services.PanelWebsite' - type: object - security: - - BearerToken: [] - summary: 获取配置 - tags: - - 网站管理 - post: - consumes: - - application/json - description: 保存网站的配置 - parameters: - - description: 网站 ID - in: path - name: id - required: true - type: integer - - description: request - in: body - name: data - required: true - schema: - $ref: '#/definitions/requests.SaveConfig' - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/controllers.SuccessResponse' - security: - - BearerToken: [] - summary: 保存配置 - tags: - - 网站管理 - /panel/website/createBackup: - post: - consumes: - - application/json - description: 创建网站的备份 - parameters: - - description: request - in: body - name: data - required: true - schema: - $ref: '#/definitions/requests.ID' - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/controllers.SuccessResponse' - security: - - BearerToken: [] - summary: 创建备份 - tags: - - 网站管理 /panel/website/defaultConfig: get: description: 获取默认首页和停止页配置 @@ -1309,123 +1146,6 @@ paths: summary: 删除备份 tags: - 网站管理 - /panel/website/log/{id}: - delete: - consumes: - - application/json - description: 清空网站的日志 - parameters: - - description: 网站 ID - in: path - name: id - required: true - type: integer - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/controllers.SuccessResponse' - security: - - BearerToken: [] - summary: 清空日志 - tags: - - 网站管理 - /panel/website/resetConfig: - post: - consumes: - - application/json - description: 重置网站的配置 - parameters: - - description: request - in: body - name: data - required: true - schema: - $ref: '#/definitions/requests.ID' - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/controllers.SuccessResponse' - security: - - BearerToken: [] - summary: 重置配置 - tags: - - 网站管理 - /panel/website/restoreBackup: - post: - consumes: - - application/json - description: 还原网站的备份 - parameters: - - description: request - in: body - name: data - required: true - schema: - $ref: '#/definitions/requests.RestoreBackup' - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/controllers.SuccessResponse' - security: - - BearerToken: [] - summary: 还原备份 - tags: - - 网站管理 - /panel/website/status/{id}: - post: - consumes: - - application/json - description: 启用或停用网站 - parameters: - - description: 网站 ID - in: path - name: id - required: true - type: integer - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/controllers.SuccessResponse' - security: - - BearerToken: [] - summary: 状态 - tags: - - 网站管理 - /panel/website/updateRemark/{id}: - post: - consumes: - - application/json - description: 更新网站的备注 - parameters: - - description: 网站 ID - in: path - name: id - required: true - type: integer - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/controllers.SuccessResponse' - security: - - BearerToken: [] - summary: 更新备注 - tags: - - 网站管理 /panel/website/uploadBackup: post: consumes: @@ -1449,6 +1169,273 @@ paths: summary: 上传备份 tags: - 网站管理 + /panel/websites: + get: + description: 获取网站管理的网站列表 + parameters: + - description: request + in: body + name: data + required: true + schema: + $ref: '#/definitions/commonrequests.Paginate' + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controllers.SuccessResponse' + - properties: + data: + $ref: '#/definitions/responses.List' + type: object + security: + - BearerToken: [] + summary: 获取网站列表 + tags: + - 网站管理 + post: + consumes: + - application/json + description: 添加网站到网站管理 + parameters: + - description: request + in: body + name: data + required: true + schema: + $ref: '#/definitions/requests.Add' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controllers.SuccessResponse' + security: + - BearerToken: [] + summary: 添加网站 + tags: + - 网站管理 + /panel/websites/{id}: + delete: + consumes: + - application/json + description: 删除网站管理的网站 + parameters: + - description: 网站 ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controllers.SuccessResponse' + security: + - BearerToken: [] + summary: 删除网站 + tags: + - 网站管理 + /panel/websites/{id}/config: + get: + consumes: + - application/json + description: 获取网站的配置 + parameters: + - description: 网站 ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controllers.SuccessResponse' + - properties: + data: + $ref: '#/definitions/services.PanelWebsite' + type: object + security: + - BearerToken: [] + summary: 获取配置 + tags: + - 网站管理 + post: + consumes: + - application/json + description: 保存网站的配置 + parameters: + - description: 网站 ID + in: path + name: id + required: true + type: integer + - description: request + in: body + name: data + required: true + schema: + $ref: '#/definitions/requests.SaveConfig' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controllers.SuccessResponse' + security: + - BearerToken: [] + summary: 保存配置 + tags: + - 网站管理 + /panel/websites/{id}/createBackup: + post: + consumes: + - application/json + description: 创建网站的备份 + parameters: + - description: 网站 ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controllers.SuccessResponse' + security: + - BearerToken: [] + summary: 创建备份 + tags: + - 网站管理 + /panel/websites/{id}/log: + delete: + consumes: + - application/json + description: 清空网站的日志 + parameters: + - description: 网站 ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controllers.SuccessResponse' + security: + - BearerToken: [] + summary: 清空日志 + tags: + - 网站管理 + /panel/websites/{id}/resetConfig: + post: + consumes: + - application/json + description: 重置网站的配置 + parameters: + - description: 网站 ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controllers.SuccessResponse' + security: + - BearerToken: [] + summary: 重置配置 + tags: + - 网站管理 + /panel/websites/{id}/restoreBackup: + post: + consumes: + - application/json + description: 还原网站的备份 + parameters: + - description: 网站 ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controllers.SuccessResponse' + security: + - BearerToken: [] + summary: 还原备份 + tags: + - 网站管理 + /panel/websites/{id}/status: + post: + consumes: + - application/json + description: 启用或停用网站 + parameters: + - description: 网站 ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controllers.SuccessResponse' + security: + - BearerToken: [] + summary: 状态 + tags: + - 网站管理 + /panel/websites/{id}/updateRemark: + post: + consumes: + - application/json + description: 更新网站的备注 + parameters: + - description: 网站 ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controllers.SuccessResponse' + security: + - BearerToken: [] + summary: 更新备注 + tags: + - 网站管理 /swagger: get: description: Swagger UI diff --git a/routes/api.go b/routes/api.go index 5711baa9..154ea9d4 100644 --- a/routes/api.go +++ b/routes/api.go @@ -36,23 +36,26 @@ func Api() { r.Post("delete", taskController.Delete) }) r.Prefix("website").Middleware(middleware.Jwt()).Group(func(r route.Router) { + websiteController := controllers.NewWebsiteController() + r.Get("defaultConfig", websiteController.GetDefaultConfig) + r.Post("defaultConfig", websiteController.SaveDefaultConfig) + r.Get("backupList", websiteController.BackupList) + r.Post("uploadBackup", websiteController.UploadBackup) + r.Post("deleteBackup", websiteController.DeleteBackup) + }) + r.Prefix("websites").Middleware(middleware.Jwt()).Group(func(r route.Router) { websiteController := controllers.NewWebsiteController() r.Get("/", websiteController.List) r.Post("/", websiteController.Add) r.Delete("{id}", websiteController.Delete) - r.Get("defaultConfig", websiteController.GetDefaultConfig) - r.Post("defaultConfig", websiteController.SaveDefaultConfig) - r.Get("config/{id}", websiteController.GetConfig) - r.Post("config/{id}", websiteController.SaveConfig) - r.Delete("log/{id}", websiteController.ClearLog) - r.Post("updateRemark/{id}", websiteController.UpdateRemark) - r.Get("backupList", websiteController.BackupList) - r.Post("createBackup", websiteController.CreateBackup) - r.Post("uploadBackup", websiteController.UploadBackup) - r.Post("restoreBackup", websiteController.RestoreBackup) - r.Post("deleteBackup", websiteController.DeleteBackup) - r.Post("resetConfig", websiteController.ResetConfig) - r.Post("status/{id}", websiteController.Status) + r.Get("{id}/config", websiteController.GetConfig) + r.Post("{id}/config", websiteController.SaveConfig) + r.Delete("{id}/log", websiteController.ClearLog) + r.Post("{id}/updateRemark", websiteController.UpdateRemark) + r.Post("{id}/createBackup", websiteController.CreateBackup) + r.Post("{id}/restoreBackup", websiteController.RestoreBackup) + r.Post("{id}/resetConfig", websiteController.ResetConfig) + r.Post("{id}/status", websiteController.Status) }) r.Prefix("cert").Middleware(middleware.Jwt()).Group(func(r route.Router) { certController := controllers.NewCertController()