mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-19 04:10:28 +08:00
提供修改网站名称的接口
This commit is contained in:
@@ -32,6 +32,10 @@ const (
|
||||
ServerStateDisabled = 0 // 已禁用
|
||||
)
|
||||
|
||||
const (
|
||||
ModelServerNameMaxLength = 60
|
||||
)
|
||||
|
||||
type ServerDAO dbs.DAO
|
||||
|
||||
func NewServerDAO() *ServerDAO {
|
||||
@@ -2784,6 +2788,14 @@ func (this *ServerDAO) UpdateServerUserId(tx *dbs.Tx, serverId int64, userId int
|
||||
return this.NotifyUpdate(tx, serverId)
|
||||
}
|
||||
|
||||
// UpdateServerName 修改服务名
|
||||
func (this *ServerDAO) UpdateServerName(tx *dbs.Tx, serverId int64, name string) error {
|
||||
return this.Query(tx).
|
||||
Pk(serverId).
|
||||
Set("name", name).
|
||||
UpdateQuickly()
|
||||
}
|
||||
|
||||
// NotifyUpdate 同步服务所在的集群
|
||||
func (this *ServerDAO) NotifyUpdate(tx *dbs.Tx, serverId int64) error {
|
||||
// 创建任务
|
||||
|
||||
@@ -2245,3 +2245,35 @@ func (this *ServerService) UpdateServerUser(ctx context.Context, req *pb.UpdateS
|
||||
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// UpdateServerName 修改服务名称
|
||||
func (this *ServerService) UpdateServerName(ctx context.Context, req *pb.UpdateServerNameRequest) (*pb.RPCSuccess, error) {
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
if userId > 0 {
|
||||
err = models.SharedServerDAO.CheckUserServer(tx, userId, req.ServerId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// 检查长度
|
||||
if len(req.Name) == 0 {
|
||||
return nil, errors.New("'name' should not be empty")
|
||||
}
|
||||
|
||||
if len([]rune(req.Name)) > models.ModelServerNameMaxLength {
|
||||
return nil, errors.New("'name' too long, max length: " + types.String(models.ModelServerNameMaxLength))
|
||||
}
|
||||
|
||||
err = models.SharedServerDAO.UpdateServerName(tx, req.ServerId, req.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user