| | |
| | | package controllers |
| | | |
| | | import ( |
| | | "basic.com/valib/logger.git" |
| | | "net/http" |
| | | "regexp" |
| | | "strconv" |
| | | "webserver/extend/code" |
| | | "webserver/extend/config" |
| | | "webserver/extend/sys" |
| | | "webserver/extend/util" |
| | | "webserver/middlewares/auth" |
| | | "webserver/service" |
| | | |
| | | "basic.com/dbapi.git" |
| | | "github.com/gin-gonic/gin" |
| | |
| | | RealMax int `json:"real_max"` //实时处理的最大路数 |
| | | } |
| | | |
| | | type ServerConfigSaveVo struct { |
| | | ServiceIpType int `json:"serviceIpType"` //0:本机ip,1:漂移ip |
| | | ServiceIp string `json:"serviceIp"` //外部服务ip |
| | | Domain string `json:"domain"` //域名 |
| | | |
| | | ImgPort int `json:"imgPort"` //图片端口 |
| | | VideoPort int `json:"videoPort"` //视频端口 |
| | | AudioPort int `json:"audioPort"` //音频端口 |
| | | type ResourceConfigVo struct { |
| | | IpType int `json:"ipType"` //0:本机ip,1:漂移ip |
| | | ServiceIp string `json:"serviceIp"` //外部服务ip |
| | | Domain string `json:"domain"` //域名 |
| | | FilePort int `json:"filePort"` |
| | | } |
| | | |
| | | type Gb28181ConfigVo struct { |
| | |
| | | Interval int `json:"interval" example:"自动校时间隔"` |
| | | NewTime string `json:"newTime" example:"手动指定时间"` |
| | | } |
| | | |
| | | /* |
| | | // @Security ApiKeyAuth |
| | | // @Summary 保存对外服务ip、录像时长以及音视频端口 |
| | | // @Description 保存对外服务ip、录像时长以及音视频端口 |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags sysset |
| | | // @Param config body controllers.ServerConfigSaveVo true "参数" |
| | | // @Success 200 {string} json "{"code":200, msg:"", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"", success:false}" |
| | | // @Router /data/api-v/sysset/saveConfig [POST] |
| | | func (sset SysSetController) SaveConfig(c *gin.Context) { |
| | | |
| | | }*/ |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 存储信息查询 |
| | |
| | | } else { |
| | | resData["server_id"] = sysconf.GetServerId() |
| | | resData["server_name"] = sysconf.GetServerName() |
| | | resData["server_port"] = sys.GetNginxListenPort() |
| | | |
| | | ipv4, mask, _ := sys.GetLocalIP(config.Server.NetworkAdapter) |
| | | gateway, _ := sys.GetDefaultRoute(config.Server.NetworkAdapter) |
| | | dns, _ := sys.GetDnsServer() |
| | |
| | | resData["dns"] = dns |
| | | resData["min_video_len"] = sysconf.CutMinDuration |
| | | resData["max_video_len"] = sysconf.CutMaxDuration |
| | | resData["alarm_ip"] = sysconf.AlarmIp |
| | | resData["alarm_port"] = sysconf.AlarmPort |
| | | resData["web_pic_ip"] = sysconf.WebPicIp |
| | | resData["web_pic_port"] = sysconf.WebPicPort |
| | | resData["es_pic_ip"] = sysconf.EsPicIp |
| | | resData["es_pic_port"] = sysconf.EsPicPort |
| | | |
| | | resData["deviceNum"] = config.Server.DeviceNum |
| | | resData["deviceType"] = config.Server.DeviceType |
| | |
| | | // @Failure 500 {string} json "{"code":500, msg:"返回错误信息", success:false}" |
| | | // @Router /data/api-v/sysset/saveDevInfo [POST] |
| | | func (sset SysSetController) SaveDevInfo(c *gin.Context) { |
| | | dev_name := c.PostForm("server_name") |
| | | var api dbapi.SysSetApi |
| | | paramBody := make(map[string]interface{}, 0) |
| | | paramBody["serverName"] = dev_name |
| | | |
| | | // 设置ip |
| | | isOk, msg := sys.SetNetworkConfig(c.PostForm("ip"), c.PostForm("subMask"), c.PostForm("gateway"), c.PostForm("dns")) |
| | | if !isOk { |
| | | util.ResponseFormat(c, code.ComError, msg) |
| | | return |
| | | paramBody := map[string]interface{}{ |
| | | "serverName": c.PostForm("server_name"), |
| | | "ip": c.PostForm("ip"), |
| | | "subMask": c.PostForm("subMask"), |
| | | "gateway": c.PostForm("gateway"), |
| | | "dns": c.PostForm("dns"), |
| | | } |
| | | |
| | | b, data := api.SaveServerInfo(paramBody) |
| | | logger.Debug("isOk b:",b, "data:", data) |
| | | if b { // 查询是否存在 |
| | | util.ResponseFormat(c, code.Success, data) |
| | | } else { // 存在及修改 不存在 即添加 |
| | |
| | | |
| | | util.ResponseFormat(c, code.Success, "配置成功") |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 获取存储对外服务信息 |
| | | // @Description 获取存储对外服务信息 |
| | | // @Produce json |
| | | // @Tags sysset |
| | | // @Success 200 {string} json "{"code":200, msg:"", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"", success:false}" |
| | | // @Router /data/api-v/sysset/getResourceConfig [get] |
| | | func (sset SysSetController) GetResourceConfig(c *gin.Context) { |
| | | var sysApi dbapi.SysSetApi |
| | | b,d := sysApi.GetResourceConfig() |
| | | if b { |
| | | util.ResponseFormat(c,code.Success,map[string]interface{}{ |
| | | "ipType":d.IpType, |
| | | "serviceIp": d.ServiceIp, |
| | | "domain": d.Domain, |
| | | "filePort": d.FilePort, |
| | | }) |
| | | } else { |
| | | util.ResponseFormat(c,code.ComError,"") |
| | | } |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 存储对外服务信息 |
| | | // @Description 存储对外服务信息 |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags sysset |
| | | // @Param reqBoby body controllers.ResourceConfigVo true "post请求,json参数" |
| | | // @Success 200 {string} json "{"code":200, msg:"", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"", success:false}" |
| | | // @Router /data/api-v/sysset/saveResourceConfig [post] |
| | | func (sset SysSetController) SaveResourceConfig(c *gin.Context) { |
| | | var reqBody ResourceConfigVo |
| | | c.BindJSON(&reqBody) |
| | | if reqBody.ServiceIp == "" && reqBody.Domain == "" { |
| | | util.ResponseFormat(c, code.RequestParamError, "") |
| | | return |
| | | } |
| | | var sysApi dbapi.SysSetApi |
| | | paramBody := util.Struct2Map(reqBody) |
| | | if b, _ := sysApi.SaveResourceConfig(paramBody); b { |
| | | util.ResponseFormat(c, code.Success, "") |
| | | } else { |
| | | util.ResponseFormat(c, code.ComError, "") |
| | | } |
| | | } |
| | | // @Summary 系统更新包上传(分块检查) |
| | | // @Description 系统更新包上传(分块检查) |
| | | // @Accept multipart/form-data |
| | | // @Produce json |
| | | // @Tags sysset |
| | | // @Param chunkNumber formData int true "当前是第几个分块" |
| | | // @Param chunkSize formData int true "每一块的大小" |
| | | // @Param currentChunkSize formData int true "当前块的大小" |
| | | // @Param identifier formData string true "整个文件的唯一标识,目前是md5" |
| | | // @Param filename formData string true "文件名称" |
| | | // @Param relativePath formData string true "文件在客户端电脑的路径" |
| | | // @Param totalChunks formData int true "文件总块数" |
| | | // @Success 200 {string} json "{"code":200, msg:"", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"", success:false}" |
| | | // @Router /data/api-v/sysset/patchUpdate [get] |
| | | func (sset SysSetController) PatchUpdateCheck(c *gin.Context) { |
| | | authDriver := auth.GenerateAuthDriver() |
| | | userM := (*authDriver).User(c) |
| | | if userM ==nil { |
| | | util.ResponseFormat(c,code.TokenNotFound,"登录过期,请登录") |
| | | return |
| | | } |
| | | chunkNumber, e1 := strconv.Atoi(c.Request.FormValue("chunkNumber")) |
| | | chunkSize, e2 := strconv.Atoi(c.Request.FormValue("chunkSize")) |
| | | currentChunkSize, e3 := strconv.Atoi(c.Request.FormValue("currentChunkSize")) |
| | | identifier := c.Request.FormValue("identifier") |
| | | filename := c.Request.FormValue("filename") |
| | | relativePath := c.Request.FormValue("relativePath") |
| | | totalChunks, e5 := strconv.Atoi(c.Request.FormValue("totalChunks")) |
| | | if identifier == "" || e1 != nil || e2 != nil || e3 != nil || e5 !=nil { |
| | | util.ResponseFormat(c,code.RequestParamError,"参数有误") |
| | | return |
| | | } |
| | | var arg = service.FileChunkCheckVo { |
| | | UserId: userM["id"].(string), |
| | | FileName: filename, |
| | | Identifier: identifier, |
| | | RelativePath: relativePath, |
| | | TotalChunks: totalChunks, |
| | | ChunkNumber: chunkNumber, |
| | | ChunkSize: chunkSize, |
| | | CurrentChunkSize:currentChunkSize, |
| | | } |
| | | var sv service.SysService |
| | | if b := sv.CheckUpdateFile(&arg);b { |
| | | c.String(http.StatusOK,"found") |
| | | } else { |
| | | c.String(http.StatusNoContent,"") |
| | | } |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 系统更新包上传 |
| | | // @Description 系统更新包上传 |
| | | // @Accept multipart/form-data |
| | | // @Produce json |
| | | // @Tags sysset |
| | | // @Param chunkNumber formData int true "当前是第几个分块" |
| | | // @Param chunkSize formData int true "每一块的大小" |
| | | // @Param currentChunkSize formData int true "当前块的大小" |
| | | // @Param totalSize formData string true "文件总大小" |
| | | // @Param identifier formData string true "整个文件的唯一标识,目前是md5" |
| | | // @Param filename formData string true "文件名称" |
| | | // @Param relativePath formData string true "文件在客户端电脑的路径" |
| | | // @Param totalChunks formData int true "文件总块数" |
| | | // @Param file formData file true "文件分片内容" |
| | | // @Success 200 {string} json "{"code":200, msg:"", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"", success:false}" |
| | | // @Router /data/api-v/sysset/patchUpdate [post] |
| | | func (sset SysSetController) PatchUpdate(c *gin.Context) { |
| | | authDriver := auth.GenerateAuthDriver() |
| | | userM := (*authDriver).User(c) |
| | | if userM == nil { |
| | | util.ResponseFormat(c, code.TokenNotFound, "登录过期,请登录") |
| | | return |
| | | } |
| | | chunkNumber, e1 := strconv.Atoi(c.Request.FormValue("chunkNumber")) |
| | | chunkSize, e2 := strconv.Atoi(c.Request.FormValue("chunkSize")) |
| | | currentChunkSize, e3 := strconv.Atoi(c.Request.FormValue("currentChunkSize")) |
| | | totalSize, e4 := strconv.ParseInt(c.Request.FormValue("totalSize"), 10, 64) |
| | | identifier := c.Request.FormValue("identifier") |
| | | filename := c.Request.FormValue("filename") |
| | | relativePath := c.Request.FormValue("relativePath") |
| | | totalChunks, e5 := strconv.Atoi(c.Request.FormValue("totalChunks")) |
| | | file, header, e6 := c.Request.FormFile("file") |
| | | if identifier == "" || e1 != nil || e2 != nil || e3 != nil || e4 != nil || e5 != nil || e6 != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数有误") |
| | | return |
| | | } |
| | | var arg = service.FileUploadVo{ |
| | | UserId: userM["id"].(string), |
| | | FileName: filename, |
| | | Identifier: identifier, |
| | | RelativePath: relativePath, |
| | | TotalSize: totalSize, |
| | | TotalChunks: totalChunks, |
| | | ChunkNumber: chunkNumber, |
| | | ChunkSize: chunkSize, |
| | | CurrentChunkSize: currentChunkSize, |
| | | File: &file, |
| | | Header: header, |
| | | } |
| | | var sv service.SysService |
| | | if b,_ := sv.PatchUpload(&arg); b { |
| | | util.ResponseFormat(c, code.Success, "") |
| | | } else { |
| | | util.ResponseFormat(c, code.ComError, "") |
| | | } |
| | | } |
| | | |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 开始升级 |
| | | // @Description 开始升级 |
| | | // @Accept multipart/form-data |
| | | // @Produce json |
| | | // @Tags sysset |
| | | // @Param identifier formData string true "整个文件的唯一标识,目前是md5" |
| | | // @Param filename formData string true "文件名称" |
| | | // @Success 200 {string} json "{"code":200, msg:"", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"", success:false}" |
| | | // @Router /data/api-v/sysset/upgrade [post] |
| | | func (sset SysSetController) Upgrade(c *gin.Context) { |
| | | identifier := c.Request.FormValue("identifier") |
| | | filename := c.Request.FormValue("filename") |
| | | if identifier == "" || filename == "" { |
| | | util.ResponseFormat(c,code.RequestParamError,"") |
| | | return |
| | | } |
| | | var sv service.SysService |
| | | if b,err := sv.Upgrade(identifier, filename);b { |
| | | util.ResponseFormat(c,code.UpgradeSuccess,"升级成功") |
| | | } else { |
| | | util.ResponseFormat(c,code.UpgradeFail,err.Error()) |
| | | } |
| | | } |