/
web.go
214 lines (207 loc) · 5.49 KB
/
web.go
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
package service
import (
"bytes"
"context"
"net"
"go-common/app/interface/main/videoup/model/archive"
"go-common/library/ecode"
"go-common/library/log"
"go-common/library/net/metadata"
"go-common/library/sync/errgroup"
)
// WebAdd add archive by web.
func (s *Service) WebAdd(c context.Context, mid int64, ap *archive.ArcParam, validated bool) (aid int64, err error) {
ip := metadata.String(c, metadata.RemoteIP)
ap.IPv6 = net.ParseIP(ip)
g := &errgroup.Group{}
ctx := context.TODO()
defer func() {
// VideoupCanotRepeat high level but basic
if err != nil && err != ecode.VideoupCanotRepeat && err != ecode.VideoupAddLimitHalfMin {
g.Go(func() error {
s.acc.DelSubmitCache(ctx, mid, ap.Title)
return nil
})
}
if err != nil && err != ecode.VideoupAddLimitHalfMin {
g.Go(func() error {
s.acc.DelHalfMin(ctx, mid)
return nil
})
}
}()
if !validated && !s.allowHalfMin(c, mid) {
log.Warn("VideoupAddLimitHalfMin mid(%d) ap(%+v) validated(%+v)", mid, ap, validated)
err = ecode.VideoupAddLimitHalfMin
return
}
if err = s.checkIdentify(c, mid, ip); err != nil {
log.Error("s.CheckIdentify mid(%d) ap(%+v) error(%v)", mid, ap, err)
return
}
if err = s.checkAddPay(c, ap, ip); err != nil {
log.Error("s.checkAddPay mid(%d) ap(%+v) error(%v)", mid, ap, err)
return
}
// 检查联合投稿
if err = s.checkAddStaff(c, ap, mid, ip); err != nil {
return
}
// pre check
if err = s.preAdd(c, mid, ap, ip, archive.UpFromWeb); err != nil {
return
}
// add
if aid, err = s.arc.Add(c, ap, ip); err != nil || aid == 0 {
return
}
g.Go(func() error {
s.dealOrder(ctx, mid, aid, ap.OrderID, ip)
return nil
})
g.Go(func() error {
s.freshFavs(ctx, mid, ap, ip)
return nil
})
g.Go(func() error {
s.acc.AddHalfMin(ctx, mid)
return nil
})
g.Go(func() error {
s.dealElec(ctx, ap.OpenElec, aid, mid, ip)
return nil
})
g.Go(func() error {
s.dealSubtitle(ctx, ap.Subtitle, aid, mid, ip)
return nil
})
// same to edit go func, 当且仅当付费设置有且开启
g.Go(func() error {
if ap.Pay != nil && ap.Pay.Open == 1 && !ap.Pay.RefuseUpdate {
if err = s.dealAddPay(ctx, ap.Pay, aid, mid, ip); err != nil {
//异步重试队列
s.asyncCh <- func() error {
return s.dealAddPay(ctx, ap.Pay, aid, mid, ip)
}
}
err = nil
}
return nil
})
g.Wait()
return
}
// WebEdit edit archive by web.
func (s *Service) WebEdit(c context.Context, ap *archive.ArcParam, mid int64) (err error) {
ip := metadata.String(c, metadata.RemoteIP)
ap.IPv6 = net.ParseIP(ip)
if err = s.checkIdentify(c, mid, ip); err != nil {
log.Error("s.CheckIdentify mid(%d) ap(%+v) error(%v)", mid, ap, err)
return
}
var (
a = &archive.Archive{}
vs = []*archive.Video{}
)
if a, vs, err = s.arc.View(c, ap.Aid, ip); err != nil {
log.Error("s.arc.View err(%v) | aid(%d) ip(%s)", err, ap.Aid, ip)
return
}
if a == nil {
log.Error("s.arc.View(%d) not found", mid)
err = ecode.ArchiveNotExist
return
}
if nvsCnt := s.checkVideosMaxLimitForEdit(vs, ap.Videos); nvsCnt > s.c.MaxAddVsCnt {
log.Error("checkVideosMaxLimitForEdit, vsCnt(%d), limit(%d), nvsCnt(%d)", len(vs), s.c.MaxAddVsCnt, nvsCnt)
err = ecode.VideoupVideosMaxLimit
return
}
if err = s.checkEditStaff(c, ap, mid, a, ip); err != nil {
return
}
// pre check
if err = s.preEdit(c, mid, a, vs, ap, ip, archive.UpFromWeb); err != nil {
return
}
// edit
if err = s.arc.Edit(c, ap, ip); err != nil {
return
}
g := &errgroup.Group{}
ctx := context.TODO()
g.Go(func() error {
s.dealElec(ctx, ap.OpenElec, ap.Aid, mid, ip)
return nil
})
g.Go(func() error {
s.dealSubtitle(ctx, ap.Subtitle, ap.Aid, mid, ip)
return nil
})
g.Go(func() error {
// web端60天之后无脑调价 && web端开放过,在60天内,不允许修改价格,但是可以修改稿件其他信息
if ap.Pay != nil && ap.Pay.Open == 1 && !ap.Pay.RefuseUpdate {
if err = s.dealAdjustPay(ctx, ap.Pay, ap.Aid, mid, ip); err != nil {
//异步重试队列
s.asyncCh <- func() error {
return s.dealAdjustPay(ctx, ap.Pay, ap.Aid, mid, ip)
}
}
err = nil
}
return nil
})
g.Wait()
return
}
// WebUpCover client upload cover.
func (s *Service) WebUpCover(c context.Context, fileType string, body []byte, mid int64) (url string, err error) {
if len(body) == 0 {
err = ecode.FileNotExists
return
}
if len(body) > s.c.Bfs.MaxFileSize {
err = ecode.FileTooLarge
return
}
url, err = s.bfs.Upload(c, fileType, bytes.NewReader(body))
if err != nil {
log.Error("s.bfs.Upload error(%v)", err)
}
return
}
// WebCmAdd add archive by web client and from business order.
func (s *Service) WebCmAdd(c context.Context, mid int64, ap *archive.ArcParam) (aid int64, err error) {
ip := metadata.String(c, metadata.RemoteIP)
ap.IPv6 = net.ParseIP(ip)
defer func() {
if err != nil && err != ecode.VideoupCanotRepeat {
s.acc.DelSubmitCache(c, ap.Mid, ap.Title)
}
}()
if ap.TypeID != archive.AdvertisingTypeID {
err = ecode.VideoupTypeidErr
log.Error("ap.TypeID is not AdvertisingTypeID mid(%d),type(%d),err(%v) ", mid, ap.TypeID, err)
return
}
if err = s.checkIdentify(c, mid, ip); err != nil {
log.Error("s.CheckIdentify mid(%d) ap(%+v) error(%v)", mid, ap, err)
return
}
// pre check
if err = s.preAdd(c, mid, ap, ip, archive.UpFromCM); err != nil {
return
}
// add
if aid, err = s.arc.Add(c, ap, ip); err != nil || aid == 0 {
return
}
g := &errgroup.Group{}
ctx := context.TODO()
g.Go(func() error {
s.dealOrder(ctx, mid, aid, ap.OrderID, ip)
return nil
})
g.Wait()
return
}