添加修改视频信息功能并测试完成
This commit is contained in:
parent
c324a1707c
commit
4a1d5eb195
11
dao/video.go
11
dao/video.go
|
|
@ -30,10 +30,19 @@ func CreateVideo(videoPath, videoName string, cameraID, authID, human, isDelete
|
||||||
|
|
||||||
func DeleteVideoByID(id, user int) int {
|
func DeleteVideoByID(id, user int) int {
|
||||||
delete_time := time.Now().Format("2006-01-02 15:04:05")
|
delete_time := time.Now().Format("2006-01-02 15:04:05")
|
||||||
DB.Debug().Where("id = ? and auth_id = ?", id, user).Delete(&Video{DeleteTime: delete_time, IsDelete: 1})
|
DB.Debug().Where("id = ? and auth_id = ?", id, user).Updates(&Video{DeleteTime: delete_time, IsDelete: 1})
|
||||||
|
DB.Debug().Where("id = ? and auth_id = ?", id, user).Delete(&Video{})
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UpdateVideo(videoPath, videoName string, cameraID, videoID, authID, human, isDelete int, createTime, endTime string, fileSize int) bool {
|
||||||
|
res := DB.Debug().Model(&Video{}).Where("id = ? and auth_id = ?", videoID, authID).Updates(Video{VideoPath: videoPath, VideoName: videoName, CameraID: cameraID, AuthId: authID, Human: human, IsDelete: isDelete, CreateTime: createTime, EndTime: endTime, FileSize: fileSize})
|
||||||
|
if res.Error != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func FindVideoByID(id, auth_id int) Video {
|
func FindVideoByID(id, auth_id int) Video {
|
||||||
var video Video
|
var video Video
|
||||||
DB.Debug().Where("id = ? and auth_id = ?", id, auth_id).Where("isdelete = ?", 0).First(&video)
|
DB.Debug().Where("id = ? and auth_id = ?", id, auth_id).Where("isdelete = ?", 0).First(&video)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt"
|
||||||
|
|
@ -28,6 +30,11 @@ func loginHandler(c *gin.Context) {
|
||||||
var req_data RLReq
|
var req_data RLReq
|
||||||
tokenString := ""
|
tokenString := ""
|
||||||
if err := c.ShouldBindJSON(&req_data); err == nil {
|
if err := c.ShouldBindJSON(&req_data); err == nil {
|
||||||
|
if len(req_data.Password) < 32 {
|
||||||
|
hasher := md5.New()
|
||||||
|
hasher.Write([]byte(req_data.Password)) // 生成密码的 MD5 散列值
|
||||||
|
req_data.Password = hex.EncodeToString(hasher.Sum(nil)) // 生成密码的 MD5 散列值
|
||||||
|
}
|
||||||
user := service.GetUser(req_data.User, req_data.Password)
|
user := service.GetUser(req_data.User, req_data.Password)
|
||||||
if user.ID != 0 {
|
if user.ID != 0 {
|
||||||
// 生成 JWT 令牌
|
// 生成 JWT 令牌
|
||||||
|
|
@ -57,6 +64,11 @@ func registerHandler(c *gin.Context) {
|
||||||
var req_data RLReq
|
var req_data RLReq
|
||||||
tokenString := ""
|
tokenString := ""
|
||||||
if err := c.ShouldBindJSON(&req_data); err == nil {
|
if err := c.ShouldBindJSON(&req_data); err == nil {
|
||||||
|
if len(req_data.Password) < 32 {
|
||||||
|
hasher := md5.New()
|
||||||
|
hasher.Write([]byte(req_data.Password)) // 生成密码的 MD5 散列值
|
||||||
|
req_data.Password = hex.EncodeToString(hasher.Sum(nil)) // 生成密码的 MD5 散列值
|
||||||
|
}
|
||||||
id := service.CreateUser(req_data.User, req_data.Password, req_data.Email)
|
id := service.CreateUser(req_data.User, req_data.Password, req_data.Email)
|
||||||
// 生成 JWT 令牌
|
// 生成 JWT 令牌
|
||||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,20 @@ type videoReq struct {
|
||||||
FileSize int `json:"file_size"`
|
FileSize int `json:"file_size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type videoUpdateReq struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
CameraID int `json:"camera_id"`
|
||||||
|
VideoPath string `json:"video_path"`
|
||||||
|
VideoName string `json:"video_name"`
|
||||||
|
AuthId int `json:"auth_id"`
|
||||||
|
Human int `json:"human"`
|
||||||
|
IsDelete int `json:"is_delete"`
|
||||||
|
CreateTime string `json:"create_time"`
|
||||||
|
EndTime string `json:"end_time"`
|
||||||
|
DeleteTime string `json:"delete_time"`
|
||||||
|
FileSize int `json:"file_size"`
|
||||||
|
}
|
||||||
|
|
||||||
// video播放视频请求
|
// video播放视频请求
|
||||||
type videoPReq struct {
|
type videoPReq struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
|
|
@ -57,6 +71,21 @@ func SetUpVideoGroup(router *gin.Engine) {
|
||||||
videoGroup.GET("/mp4", GetVideo)
|
videoGroup.GET("/mp4", GetVideo)
|
||||||
videoGroup.POST("/delay", DelayVideo)
|
videoGroup.POST("/delay", DelayVideo)
|
||||||
videoGroup.POST("/delete", DeleteVideo)
|
videoGroup.POST("/delete", DeleteVideo)
|
||||||
|
videoGroup.POST("/update", UpdateVideo)
|
||||||
|
}
|
||||||
|
func UpdateVideo(c *gin.Context) {
|
||||||
|
var video_req videoUpdateReq
|
||||||
|
user_id, _ := c.Get("id")
|
||||||
|
if err := c.ShouldBindJSON(&video_req); err == nil {
|
||||||
|
res := service.UpdateVideo(video_req.VideoPath, video_req.VideoName, video_req.CameraID, video_req.ID, int(user_id.(float64)), video_req.Human, video_req.IsDelete, video_req.CreateTime, video_req.EndTime, video_req.FileSize)
|
||||||
|
if !res {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "update video failed", "code": 1, "message": "failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"code": 0, "message": "success"})
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "code": 1, "message": "failed"})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetVideo(c *gin.Context) {
|
func GetVideo(c *gin.Context) {
|
||||||
|
|
|
||||||
|
|
@ -33,3 +33,35 @@ func CreateVideo(videoPath, videoName string, cameraID, authID, human, isDelete
|
||||||
func DeleteVideo(id, user int) int {
|
func DeleteVideo(id, user int) int {
|
||||||
return dao.DeleteVideoByID(id, user)
|
return dao.DeleteVideoByID(id, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UpdateVideo(videoPath, videoName string, cameraID, videoID, authID, human, isDelete int, createTime, endTime string, fileSize int) bool {
|
||||||
|
video := GetVideo(videoID, authID)
|
||||||
|
if video.ID == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if videoPath == "" {
|
||||||
|
videoPath = video.VideoPath
|
||||||
|
}
|
||||||
|
if videoName == "" {
|
||||||
|
videoName = video.VideoName
|
||||||
|
}
|
||||||
|
if cameraID == 0 {
|
||||||
|
cameraID = video.CameraID
|
||||||
|
}
|
||||||
|
if human == 0 {
|
||||||
|
human = video.Human
|
||||||
|
}
|
||||||
|
if isDelete == 0 {
|
||||||
|
isDelete = video.IsDelete
|
||||||
|
}
|
||||||
|
if createTime == "" {
|
||||||
|
createTime = video.CreateTime
|
||||||
|
}
|
||||||
|
if endTime == "" {
|
||||||
|
endTime = video.EndTime
|
||||||
|
}
|
||||||
|
if fileSize == 0 {
|
||||||
|
fileSize = video.FileSize
|
||||||
|
}
|
||||||
|
return dao.UpdateVideo(videoPath, videoName, cameraID, videoID, authID, human, isDelete, createTime, endTime, fileSize)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue