修复视频添加的视频id未添加问题

This commit is contained in:
lijun 2024-05-21 11:10:21 +08:00
parent 6ab89f4369
commit c324a1707c
6 changed files with 12 additions and 10 deletions

View File

@ -8,7 +8,7 @@ import (
var DB *gorm.DB
func Init() {
dsn := "video_t:SDssrzALGiidPcjE@tcp(127.0.0.1:3306)/video_t?charset=utf8mb4&parseTime=True&loc=Local"
dsn := "root:lj123456@tcp(127.0.0.1:3306)/video_t?charset=utf8mb4&parseTime=True&loc=Local"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {

View File

@ -19,8 +19,8 @@ type Video struct {
FileSize int `gorm:"column:file_size"`
}
func CreateVideo(videoPath, videoName string, authID, human, isDelete int, createTime, endTime string, fileSize int) uint {
video := Video{VideoPath: videoPath, VideoName: videoName, AuthId: authID, Human: human, IsDelete: isDelete, CreateTime: createTime, EndTime: endTime, FileSize: fileSize}
func CreateVideo(videoPath, videoName string, cameraID, authID, human, isDelete int, createTime, endTime string, fileSize int) uint {
video := Video{VideoPath: videoPath, VideoName: videoName, CameraID: cameraID, AuthId: authID, Human: human, IsDelete: isDelete, CreateTime: createTime, EndTime: endTime, FileSize: fileSize}
res := DB.Debug().Create(&video)
if res.Error != nil {
return 0

View File

@ -62,7 +62,7 @@ func registerHandler(c *gin.Context) {
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"username": req_data.User,
"id": id,
"exp": time.Now().Add(time.Hour * 100).Unix(), // 令牌过期时间, 1分钟后过期
"exp": time.Now().Add(time.Hour * 10).Unix(), // 令牌过期时间, 1分钟后过期
})
tokenString, err = token.SignedString(signingKey)
if err != nil {
@ -72,7 +72,7 @@ func registerHandler(c *gin.Context) {
c.JSON(400, gin.H{"error": err.Error()})
}
fmt.Println(req_data)
worker.SetRedisWithExpire(req_data.User, tokenString, 600) // 设置过期时间为10分钟
worker.SetRedisWithExpire(tokenString, tokenString, time.Hour*10) // 设置过期时间为10分钟
// 返回令牌
c.JSON(200, gin.H{"token": tokenString, "username": req_data.User})
}

View File

@ -1,6 +1,7 @@
package handler
import (
"fmt"
"github.com/gin-gonic/gin"
"net/http"
"os"
@ -91,7 +92,8 @@ func CreateVideo(c *gin.Context) {
var video_req videoReq
user_id, _ := c.Get("id")
if err := c.ShouldBindJSON(&video_req); err == nil {
id := service.CreateVideo(video_req.VideoPath, video_req.VideoName, int(user_id.(float64)), video_req.Human, video_req.IsDelete, video_req.CreateTime, video_req.EndTime, video_req.FileSize)
fmt.Println(video_req)
id := service.CreateVideo(video_req.VideoPath, video_req.VideoName, video_req.CameraID, int(user_id.(float64)), video_req.Human, video_req.IsDelete, video_req.CreateTime, video_req.EndTime, video_req.FileSize)
if id == 0 {
c.JSON(http.StatusBadRequest, gin.H{"error": "create video failed", "code": 1, "message": "failed"})
return

View File

@ -26,8 +26,8 @@ func DelayVideo(id, auth_id, day int) {
dao.DelayVideo(id, auth_id, day)
}
func CreateVideo(videoPath, videoName string, authID, human, isDelete int, createTime, endTime string, fileSize int) uint {
return dao.CreateVideo(videoPath, videoName, authID, human, isDelete, createTime, endTime, fileSize)
func CreateVideo(videoPath, videoName string, cameraID, authID, human, isDelete int, createTime, endTime string, fileSize int) uint {
return dao.CreateVideo(videoPath, videoName, cameraID, authID, human, isDelete, createTime, endTime, fileSize)
}
func DeleteVideo(id, user int) int {

View File

@ -17,8 +17,8 @@ func InitRedis() {
// 连接redis
redisClient = redis.NewClient(&redis.Options{
Addr: "127.0.0.1:6379", // Redis 服务器地址
Password: "lj502138", // 如果 Redis 设置了密码
DB: 2, // 使用的数据库编号
Password: "", // 如果 Redis 设置了密码
DB: 0, // 使用的数据库编号
})
// 验证 Redis 客户端是否可以正常工作