TSINGSEE青犀视频EasyNVR平台在前几次的更新中,已经支持修改页面标题和底部版权信息了,但是目前EasyNVR修改自定义标题和CopyRight必须是永久授权才能修改。
对于一些获得了临时授权的用户来说,如果要修改自定义内容,则无法实现。因此现需要改为不限制授权方式就可以自定义修改。
在目前的逻辑下,前端将如果不是永久授权,就显示为只可读,不可以修改的样式;后端也在修改自定义标题和copyright的地方添加了限制,先判断是否为永久授权,如果不是则不允许修改,是永久授权才允许修改。
/**
修改自定义配置
*/
func UpdateCustom(c *gin.Context) {
var customConfig CustomConfig
if err := c.ShouldBind(&customConfig); err != nil {
c.AbortWithStatusJSON(400, err.Error())
return
}
plays := customConfig.Plays
var playProtocolEnable string
sort.Sort(plays)
for i := range plays {
playProtocolEnable += strconv.FormatInt(int64(plays[i].IsEnable), 10)
if i != len(plays)-1 {
playProtocolEnable += ","
}
}
// 保存到文件
err := utils.SaveToConf("custom_config", map[string]string{
"advert_enable": strconv.FormatInt(int64(customConfig.AdvertEnable), 10),
"default_protocol": customConfig.PlayDefaultProtocol,
"default_player": customConfig.DefaultPlayer,
"play_protocol_enable": playProtocolEnable,
"title": customConfig.Title,
"copyRight": customConfig.CopyRight,
})
if err != nil {
c.AbortWithStatusJSON(500, err.Error())
return
}
c.IndentedJSON(http.StatusOK, "ok")
}
因此根据该逻辑,我们需要在修改自定义标题和copyright的地方去除对永久授权的判断和限制,直接就允许修改就行了。获取自定义标题和copyright的地方也是这样,去除是否是永久授权的判断。
/**
获取自定义配置
*/
func GetCustom(c *gin.Context) {
customConfig := utils.Conf().Section("custom_config")
defaultProtocol := customConfig.Key("default_protocol").String()
defaultPlayer := customConfig.Key("default_player").String()
unPlayerLogo := customConfig.Key("un_play_logo").MustBool(false)
playProtocol := customConfig.Key("play_protocol").String()
protocol := strings.Split(playProtocol, ",")
playProtocolEnable := customConfig.Key("play_protocol_enable").String()
enable := strings.Split(playProtocolEnable, ",")
rsa := utils.Conf().Section("base_config").Key("rsa").MustBool(false)
var plays plays
for i := range protocol {
isEnable := uint(0)
if enable[i] == "true" || enable[i] == "1" {
isEnable = 1
}
play := Play{
Id: i + 1,
Name: protocol[i],
IsEnable: isEnable,
}
plays = append(plays, play)
}
title := customConfig.Key("title").MustString("")
copyRight := customConfig.Key("copyRight").MustString("")
var data = CustomConfig{
Title: title,
CopyRight: copyRight,
AdvertEnable: customConfig.Key("advert_enable").MustUint(0),
PlayDefaultProtocol: defaultProtocol,
Plays: plays,
DefaultPlayer: defaultPlayer,
UnPlayerLogo: unPlayerLogo,
Rsa: rsa,
}
c.IndentedJSON(http.StatusOK, data)
}
修改后效果如下,无论在什么授权下,都可直接修改自定义内容: