-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash.go
More file actions
81 lines (70 loc) · 2.24 KB
/
Copy pathhash.go
File metadata and controls
81 lines (70 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package conversion
import (
"errors"
"github.com/xormsharp/xorm"
)
// HashType ...
type HashType string
// TypeOther ...
const (
HashTypeOther HashType = "other"
HashTypeVideo HashType = "video"
HashTypeSlice HashType = "slice"
HashTypePoster HashType = "poster"
HashTypeThumb HashType = "thumb"
HashTypeCaption HashType = "caption"
)
// Hash ...
type Hash struct {
Model `xorm:"extends"`
Checksum string `xorm:"default() checksum" json:"checksum"` //sum值
HashType HashType `xorm:"default() hash_type" json:"hash_type"` //类型
Episode string `xorm:"default() episode" json:"episode"` //总集数
Name string `xorm:"default() name" json:"name"` //banno
Hash string `xorm:"default() hash" json:"hash"` //哈希地址
Sharpness string `xorm:"default() sharpness" json:"sharpness"` //清晰度
Caption string `xorm:"default() caption" json:"caption"` //字幕
Encrypt bool `xorm:"default() encrypt" json:"encrypt"` //加密
Key string `xorm:"default() key" json:"key"` //秘钥
M3U8 string `xorm:"default() m3u8" json:"m3u8"` //M3U8名
SegmentFile string `xorm:"default() segment_file" json:"segment_file"` //ts切片名
Resource string `xorm:" default() resource" json:"resource"` //资源地址
}
// Table ...
func (h *Hash) Table() interface{} {
return &Hash{}
}
func init() {
registerTable(&Hash{})
}
// Sync ...
func (h *Hash) Sync() error {
return _database.Sync2(h)
}
// AllHash ...
func AllHash(session *xorm.Session, limit int, start ...int) (unfins *[]*Hash, e error) {
unfins = new([]*Hash)
session = MustSession(session)
if limit > 0 {
session = session.Limit(limit, start...)
}
if err := session.Find(unfins); err != nil {
return nil, err
}
return unfins, nil
}
// FindHash ...
func FindHash(session *xorm.Session, checksum string) (unfin *Hash, e error) {
unfin = new(Hash)
b, e := MustSession(session).Where("checksum = ?", checksum).Get(unfin)
if e != nil || !b {
return nil, errors.New("hash not found")
}
return unfin, nil
}
// Clone ...
func (h *Hash) Clone() (n *Hash) {
n = new(Hash)
*n = *h
return
}