2023-12-21 22:17:40 +08:00
|
|
|
package dbstruct
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"service/library/wishjson"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 图片
|
2024-02-06 02:51:24 +08:00
|
|
|
const (
|
|
|
|
ImageStatusResizeInit = 0
|
|
|
|
ImageStatusResizeDone = 100
|
|
|
|
ImageStatusResizeFail = 101
|
|
|
|
)
|
|
|
|
|
2024-05-07 10:50:40 +08:00
|
|
|
// 视频
|
|
|
|
const (
|
|
|
|
VideoStatusResizeInit = 0
|
|
|
|
VideoStatusResizeDone = 100
|
|
|
|
VideoStatusResizeFail = 101
|
|
|
|
)
|
|
|
|
|
2023-12-21 22:17:40 +08:00
|
|
|
type Image struct {
|
2024-02-06 02:51:24 +08:00
|
|
|
Id int64 `json:"id" bson:"_id"` // 图片id
|
|
|
|
Ct int64 `json:"ct" bson:"ct"` // 创建时间
|
|
|
|
Ut int64 `json:"ut" bson:"ut"` // 更新时间
|
|
|
|
SrcId string `json:"src_id" bson:"src_id"` // 源id
|
|
|
|
SizeSrc int64 `json:"size_src" bson:"size_src"` // 原图片大小
|
|
|
|
SrcId720 string `json:"src_id_720" bson:"src_id_720"` // 720P图片
|
|
|
|
Size720 int64 `json:"size_720" bson:"size_720"` // 720P图片大小
|
|
|
|
SrcId1080 string `json:"src_id_1080" bson:"src_id_1080"` // 1080P图片
|
|
|
|
Size1080 int64 `json:"size_1080" bson:"size_1080"` // 1080P图片大小
|
|
|
|
SrcId1440 string `json:"src_id_1440" bson:"src_id_1440"` // 1440P图片
|
|
|
|
Size1440 int64 `json:"size_1440" bson:"size_1440"` // 1440P图片大小
|
|
|
|
Status int `json:"status" bson:"status"` // 状态
|
|
|
|
ResizeT int64 `json:"resize_t" bson:"resize_t"` // 压缩时间
|
|
|
|
MD5 string `json:"md5" bson:"md5"` // 视频md5
|
|
|
|
W int64 `json:"w" bson:"w"` // 宽
|
|
|
|
H int64 `json:"h" bson:"h"` // 高
|
|
|
|
Fmt string `json:"fmt" bson:"fmt"` // 图片格式
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Image) SelectMinSizeOssId() string {
|
|
|
|
if i == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
if len(i.SrcId720) > 0 && i.Size720 < i.SizeSrc {
|
|
|
|
return i.SrcId720
|
|
|
|
}
|
|
|
|
return i.SrcId
|
2023-12-21 22:17:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type ToCImage struct {
|
|
|
|
Id int64 `json:"id"` // 图片id
|
|
|
|
W int64 `json:"w"` // 宽
|
|
|
|
H int64 `json:"h"` // 高
|
|
|
|
Fmt string `json:"fmt"` // 图片格式
|
|
|
|
Urls []string `json:"urls"` // 图片展示地址
|
|
|
|
}
|
|
|
|
|
|
|
|
// 视频
|
|
|
|
type Video struct {
|
|
|
|
Id int64 `json:"id" bson:"_id"` // 视频id
|
|
|
|
Ct int64 `json:"ct" bson:"ct"` // 创建时间
|
|
|
|
Ut int64 `json:"ut" bson:"ut"` // 更新时间
|
|
|
|
SrcId string `json:"src_id" bson:"src_id"` // 源id
|
2024-05-07 10:50:40 +08:00
|
|
|
SizeSrc int64 `json:"size_src" bson:"size_src"` // 原视频大小
|
|
|
|
SrcId720 string `json:"src_id_720" bson:"src_id_720"` // 720P视频
|
|
|
|
Size720 int64 `json:"size_720" bson:"size_720"` // 720P视频大小
|
|
|
|
SrcIdH264 string `json:"src_id_h264" bson:"src_id_h264"` // 原视频h264 mp4
|
|
|
|
SizeH264 int64 `json:"size_h264" bson:"size_h264"` // 原视频h264 mp4大小
|
|
|
|
Status int `json:"status" bson:"status"` // 状态
|
|
|
|
ResizeT int64 `json:"resize_t" bson:"resize_t"` // 压缩时间
|
2023-12-21 22:17:40 +08:00
|
|
|
CoverSrcId string `json:"cover_src_id" bson:"cover_src_id"` // cover srcId
|
|
|
|
CoverId int64 `json:"cover_id" bson:"cover_id"` // 封面id
|
|
|
|
MD5 string `json:"md5" bson:"md5"` // 视频md5
|
|
|
|
Dur int64 `json:"dur" bson:"dur"` // 视频时长
|
|
|
|
Fmt string `json:"fmt" bson:"fmt"`
|
|
|
|
}
|
|
|
|
|
2024-07-28 14:53:34 +08:00
|
|
|
var SrcVidMap = map[int64]bool{
|
|
|
|
130337: true,
|
|
|
|
130333: true,
|
|
|
|
130319: true,
|
|
|
|
127635: true,
|
|
|
|
126370: true,
|
|
|
|
126360: true,
|
|
|
|
123141: true,
|
|
|
|
123091: true,
|
|
|
|
120215: true,
|
|
|
|
120194: true,
|
|
|
|
120186: true,
|
|
|
|
120184: true,
|
|
|
|
118368: true,
|
|
|
|
118124: true,
|
|
|
|
117231: true,
|
|
|
|
117209: true,
|
|
|
|
113009: true,
|
|
|
|
112996: true,
|
|
|
|
111162: true,
|
|
|
|
110511: true,
|
|
|
|
109734: true,
|
|
|
|
108184: true,
|
|
|
|
107836: true,
|
|
|
|
106902: true,
|
|
|
|
104865: true,
|
|
|
|
104863: true,
|
|
|
|
103998: true,
|
|
|
|
103996: true,
|
|
|
|
103982: true,
|
|
|
|
103752: true,
|
|
|
|
100327: true,
|
|
|
|
100315: true,
|
|
|
|
99188: true,
|
|
|
|
97052: true,
|
|
|
|
97044: true,
|
|
|
|
95953: true,
|
|
|
|
95934: true,
|
|
|
|
95063: true,
|
|
|
|
94282: true,
|
|
|
|
93427: true,
|
|
|
|
92073: true,
|
|
|
|
91566: true,
|
|
|
|
91546: true,
|
|
|
|
90964: true,
|
|
|
|
90962: true,
|
2024-08-03 18:09:09 +08:00
|
|
|
128309: true,
|
|
|
|
124206: true,
|
|
|
|
109374: true,
|
|
|
|
108582: true,
|
|
|
|
108580: true,
|
|
|
|
102579: true,
|
2024-07-28 14:53:34 +08:00
|
|
|
}
|
|
|
|
|
2024-07-13 13:12:34 +08:00
|
|
|
func (i *Video) SelectMinSizeOssId() string {
|
2024-07-28 14:53:34 +08:00
|
|
|
if SrcVidMap[i.Id] {
|
2024-07-28 14:21:24 +08:00
|
|
|
return i.SrcId
|
|
|
|
}
|
2024-07-13 13:12:34 +08:00
|
|
|
if i == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
if i.Status == VideoStatusResizeDone && len(i.SrcId720) > 0 && i.Size720 < i.SizeSrc {
|
|
|
|
return i.SrcId720
|
|
|
|
}
|
|
|
|
return i.SrcId
|
|
|
|
}
|
|
|
|
|
2023-12-21 22:17:40 +08:00
|
|
|
type ToCVideo struct {
|
|
|
|
Id int64 `json:"id"` // 视频id
|
|
|
|
Dur int64 `json:"dur"` // 视频时
|
|
|
|
CoverUrls []string `json:"cover_urls"` // 视频封面地址
|
2024-01-16 21:44:58 +08:00
|
|
|
CoverW int64 `json:"cover_w"` // 封面宽
|
|
|
|
CoverH int64 `json:"cover_h"` // 封面高
|
|
|
|
CoverFmt string `json:"cover_fmt"` // 封面图片格式
|
2023-12-21 22:17:40 +08:00
|
|
|
Urls []string `json:"urls"` // 视频地址
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewImageFromJson(item any) (img *Image, err error) {
|
|
|
|
j := wishjson.New(item)
|
|
|
|
img = &Image{
|
|
|
|
SrcId: j.Get("src_id").MustPhpString(),
|
|
|
|
MD5: j.Get("md5").MustPhpString(),
|
|
|
|
W: j.Get("w").MustPhpInt(),
|
|
|
|
H: j.Get("h").MustPhpInt(),
|
|
|
|
Fmt: j.Get("fmt").MustPhpString(),
|
|
|
|
}
|
|
|
|
if img.SrcId == "" {
|
|
|
|
err = errors.New("invalid image object with null src_id")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if img.MD5 == "" {
|
|
|
|
err = errors.New("invalid image object with null md5")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if img.W == 0 {
|
|
|
|
err = errors.New("invalid image object with zero-width")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if img.H == 0 {
|
|
|
|
err = errors.New("invalid image object with zero-height")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if img.Fmt == "" {
|
|
|
|
err = errors.New("invalid image object with null fmt")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewVideoFromJson(item any) (vid *Video, err error) {
|
|
|
|
j := wishjson.New(item)
|
|
|
|
vid = &Video{
|
|
|
|
SrcId: j.Get("src_id").MustPhpString(),
|
|
|
|
CoverSrcId: j.Get("cover_src_id").MustPhpString(),
|
|
|
|
CoverId: j.Get("cover_id").MustPhpInt(),
|
|
|
|
MD5: j.Get("md5").MustPhpString(),
|
|
|
|
Dur: j.Get("dur").MustPhpInt(),
|
|
|
|
Fmt: j.Get("fmt").MustPhpString(),
|
|
|
|
}
|
|
|
|
if vid.SrcId == "" {
|
|
|
|
err = errors.New("invalid video object with null src_id")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if vid.CoverId == 0 {
|
|
|
|
err = errors.New("invalid video object with zero cover_id")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if vid.MD5 == "" {
|
|
|
|
err = errors.New("invalid video object with null md5")
|
|
|
|
return
|
|
|
|
}
|
2024-05-17 14:08:15 +08:00
|
|
|
//if vid.Dur == 0 {
|
|
|
|
// err = errors.New("invalid video object with zero dur")
|
|
|
|
// return
|
|
|
|
//}
|
2023-12-21 22:17:40 +08:00
|
|
|
if vid.Fmt == "" {
|
|
|
|
err = errors.New("invalid video object with null fmt")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|