初始
This commit is contained in:
49
api/video_hat/video_playback11/all_video_data11.1.go
Normal file
49
api/video_hat/video_playback11/all_video_data11.1.go
Normal file
@ -0,0 +1,49 @@
|
||||
package video_playback11
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/tiger1103/gfast/v3/api/constant"
|
||||
)
|
||||
|
||||
// 回放路由
|
||||
type VideoPlayback struct{}
|
||||
|
||||
// 管理员下所有视频
|
||||
type GetAllVideodataReq struct {
|
||||
g.Meta `path:"/video/data" method:"post" tags:"视频安全帽相关" summary:"获取管理员账号下所有设备的视频记录日期"`
|
||||
}
|
||||
|
||||
type GetAllVideodataRes struct {
|
||||
List UserData `json:"list"`
|
||||
}
|
||||
|
||||
func (v VideoPlayback) GetAllVideodata(ctx context.Context, req *GetAllVideodataReq) (res *GetAllVideodataRes, err error) {
|
||||
res = new(GetAllVideodataRes)
|
||||
data := url.Values{}
|
||||
data.Set("admin_id", constant.AdminId)
|
||||
data.Set("token", constant.Token)
|
||||
|
||||
resp, err := http.PostForm("https://caps.runde.pro/api/index.php?ctl=video&act=get_path_list", data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
respBody, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(respBody, &res.List)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
76
api/video_hat/video_playback11/data_videoplayback11.2.go
Normal file
76
api/video_hat/video_playback11/data_videoplayback11.2.go
Normal file
@ -0,0 +1,76 @@
|
||||
package video_playback11
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/tiger1103/gfast/v3/api/constant"
|
||||
"golang.org/x/net/context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// 管理员下所有视频
|
||||
type GetDataVideoPlaybackReq struct {
|
||||
g.Meta `path:"/video/playback" method:"post" tags:"视频安全帽相关" summary:"根据日期获取设备视频列表"`
|
||||
Year string `json:"year" dc:"年"`
|
||||
Month string `json:"month" dc:"月"`
|
||||
Day string `json:"day" dc:"日"`
|
||||
UID string `json:"uid" dc:"平台的用户ID"`
|
||||
}
|
||||
|
||||
type GetDataVideoPlaybackRes struct {
|
||||
List DataVideoPlayRes `json:"list"`
|
||||
}
|
||||
|
||||
type AnyString string
|
||||
|
||||
func (a *AnyString) UnmarshalJSON(data []byte) error {
|
||||
if string(data) == "null" {
|
||||
return nil
|
||||
}
|
||||
// 尝试解析为字符串
|
||||
var str string
|
||||
if err := json.Unmarshal(data, &str); err == nil {
|
||||
*a = AnyString(str)
|
||||
return nil
|
||||
}
|
||||
// 尝试解析为数字并转换为字符串
|
||||
var num int
|
||||
if err := json.Unmarshal(data, &num); err == nil {
|
||||
*a = AnyString(fmt.Sprintf("%d", num))
|
||||
return nil
|
||||
}
|
||||
return errors.New("msg_code is neither a string nor a number")
|
||||
}
|
||||
|
||||
func (v VideoPlayback) GetDataVideoPlayback(ctx context.Context, req *GetDataVideoPlaybackReq) (res *GetDataVideoPlaybackRes, err error) {
|
||||
res = new(GetDataVideoPlaybackRes)
|
||||
data := url.Values{}
|
||||
data.Set("token", constant.Token)
|
||||
data.Set("admin_id", constant.AdminId)
|
||||
data.Set("uid", req.UID)
|
||||
data.Set("year", req.Year)
|
||||
data.Set("month", req.Month)
|
||||
data.Set("day", req.Day)
|
||||
|
||||
resp, err := http.PostForm("https://caps.runde.pro/api/index.php?ctl=video&act=get_video_list_v1", data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
respBody, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(respBody, &res.List)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
24
api/video_hat/video_playback11/videopalyback_model.go
Normal file
24
api/video_hat/video_playback11/videopalyback_model.go
Normal file
@ -0,0 +1,24 @@
|
||||
package video_playback11
|
||||
|
||||
// 11.1 获取管理员账号下所有设备包含视频记录日期
|
||||
type UserData map[string]UserYears
|
||||
type UserYears map[string]UserMonths
|
||||
type UserMonths map[string][]string
|
||||
|
||||
// 11.2 根据日期获取设备视频列表 定义外层结构体
|
||||
type DataVideoPlayRes struct {
|
||||
Status bool `json:"status"`
|
||||
Msg string `json:"msg"`
|
||||
Data []Video `json:"data"`
|
||||
MsgCode interface{} `json:"msg_code"`
|
||||
}
|
||||
|
||||
// 定义Video结构体,表示data字段中的单个元素
|
||||
type Video struct {
|
||||
ID string `json:"id"`
|
||||
UserID string `json:"user_id"`
|
||||
URL string `json:"url"`
|
||||
CTime string `json:"ctime"`
|
||||
Content *string `json:"content"` // 使用指针处理可能为null的字段
|
||||
PlayTime string `json:"play_time"`
|
||||
}
|
Reference in New Issue
Block a user