Translate Chinese comments, log/error messages, validator labels and Swagger annotations to English throughout the source code, generated Swagger docs, config files and CI workflows. Make the English README primary: README.md now holds the English docs and README_EN.md holds the Chinese version, with cross-language links updated accordingly. Note: the generated docs/ swagger files were translated in place; run `go generate ./...` (swag init) to regenerate them from the now-English annotations when a Go toolchain is available. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
106 lines
3.1 KiB
Go
106 lines
3.1 KiB
Go
package admin
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/lejianwen/rustdesk-api/v2/global"
|
|
"github.com/lejianwen/rustdesk-api/v2/http/request/admin"
|
|
"github.com/lejianwen/rustdesk-api/v2/http/response"
|
|
"github.com/lejianwen/rustdesk-api/v2/service"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type ShareRecord struct {
|
|
}
|
|
|
|
// List list
|
|
// @Tags share record
|
|
// @Summary share record list
|
|
// @Description share record list
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param user_id query int false "userID"
|
|
// @Param page query int false "page number"
|
|
// @Param page_size query int false "page size"
|
|
// @Success 200 {object} response.Response
|
|
// @Failure 500 {object} response.Response
|
|
// @Router /admin/share_record/list [get]
|
|
// @Security token
|
|
func (sr *ShareRecord) List(c *gin.Context) {
|
|
query := &admin.ShareRecordQuery{}
|
|
if err := c.ShouldBindQuery(query); err != nil {
|
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
|
return
|
|
}
|
|
res := service.AllService.ShareRecordService.List(query.Page, query.PageSize, func(tx *gorm.DB) {
|
|
if query.UserId > 0 {
|
|
tx.Where("user_id = ?", query.UserId)
|
|
}
|
|
})
|
|
response.Success(c, res)
|
|
}
|
|
|
|
// Delete delete
|
|
// @Tags share record
|
|
// @Summary delete share record
|
|
// @Description delete share record
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param body body admin.ShareRecordForm true "share record info"
|
|
// @Success 200 {object} response.Response
|
|
// @Failure 500 {object} response.Response
|
|
// @Router /admin/share_record/delete [post]
|
|
// @Security token
|
|
func (sr *ShareRecord) Delete(c *gin.Context) {
|
|
f := &admin.ShareRecordForm{}
|
|
if err := c.ShouldBindJSON(f); err != nil {
|
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
|
return
|
|
}
|
|
id := f.Id
|
|
errList := global.Validator.ValidVar(c, id, "required,gt=0")
|
|
if len(errList) > 0 {
|
|
response.Fail(c, 101, errList[0])
|
|
return
|
|
}
|
|
i := service.AllService.ShareRecordService.InfoById(f.Id)
|
|
if i.Id > 0 {
|
|
err := service.AllService.ShareRecordService.Delete(i)
|
|
if err == nil {
|
|
response.Success(c, nil)
|
|
return
|
|
}
|
|
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
|
return
|
|
}
|
|
response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
|
|
}
|
|
|
|
// BatchDelete batch delete
|
|
// @Tags share record
|
|
// @Summary batch share records
|
|
// @Description batch share records
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param body body admin.PeerShareRecordBatchDeleteForm true "id"
|
|
// @Success 200 {object} response.Response
|
|
// @Failure 500 {object} response.Response
|
|
// @Router /admin/share_record/batchDelete [post]
|
|
// @Security token
|
|
func (sr *ShareRecord) BatchDelete(c *gin.Context) {
|
|
f := &admin.PeerShareRecordBatchDeleteForm{}
|
|
if err := c.ShouldBindJSON(f); err != nil {
|
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
|
return
|
|
}
|
|
if len(f.Ids) == 0 {
|
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
|
|
return
|
|
}
|
|
err := service.AllService.ShareRecordService.BatchDelete(f.Ids)
|
|
if err != nil {
|
|
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
|
return
|
|
}
|
|
response.Success(c, nil)
|
|
}
|