随笔 - 1506  文章 - 1  评论 - 7  阅读 - 58万

RTSP协议视频监控智能分析系统EasyNVR开发临时授权下自定义标题功能记录

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)
}

修改后效果如下,无论在什么授权下,都可直接修改自定义内容:

posted on   EasyNVR  阅读(120)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 提示词工程——AI应用必不可少的技术
· 字符编码:从基础到乱码解决
· 地球OL攻略 —— 某应届生求职总结
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示