1
|
package v1
|
1
|
package v1
|
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
|
|
4
|
+ "fmt"
|
4
|
"opp/controllers"
|
5
|
"opp/controllers"
|
5
|
"opp/protocol"
|
6
|
"opp/protocol"
|
6
|
"opp/services/upload"
|
7
|
"opp/services/upload"
|
|
@@ -18,25 +19,27 @@ func (this *UploadController) Image() { |
|
@@ -18,25 +19,27 @@ func (this *UploadController) Image() { |
18
|
var (
|
19
|
var (
|
19
|
msg *protocol.ResponseMessage
|
20
|
msg *protocol.ResponseMessage
|
20
|
err error
|
21
|
err error
|
|
|
22
|
+ rsp *protocol.FileResponse = &protocol.FileResponse{}
|
21
|
)
|
23
|
)
|
22
|
defer func() {
|
24
|
defer func() {
|
23
|
this.Resp(msg)
|
25
|
this.Resp(msg)
|
24
|
}()
|
26
|
}()
|
25
|
var request = &protocol.FileRequest{}
|
27
|
var request = &protocol.FileRequest{}
|
26
|
- //if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{
|
|
|
27
|
- // log.Error(err)
|
|
|
28
|
- // msg = protocol.ReturnResponse(1)
|
|
|
29
|
- // return
|
|
|
30
|
- //}
|
|
|
31
|
- //if b,m :=this.Valid(request);!b{
|
|
|
32
|
- // msg = m
|
|
|
33
|
- // return
|
|
|
34
|
- //}
|
|
|
35
|
- if request.Files, err = this.GetFiles("image"); err != nil {
|
|
|
36
|
- log.Error(err)
|
|
|
37
|
- return
|
28
|
+ for i := 1; i <= 9; i++ {
|
|
|
29
|
+ var tmp *protocol.FileResponse
|
|
|
30
|
+ key := fmt.Sprintf("%v%v", "image", i)
|
|
|
31
|
+ if request.Files, err = this.GetFiles(key); err != nil {
|
|
|
32
|
+ log.Error(key, err)
|
|
|
33
|
+ err = nil
|
|
|
34
|
+ break
|
|
|
35
|
+ }
|
|
|
36
|
+ if tmp, err = upload.Image(request); err != nil {
|
|
|
37
|
+ log.Error(err)
|
|
|
38
|
+ return
|
|
|
39
|
+ }
|
|
|
40
|
+ rsp.Paths = append(rsp.Paths, tmp.Paths...)
|
38
|
}
|
41
|
}
|
39
|
- msg = protocol.NewReturnResponse(upload.Image(request))
|
42
|
+ msg = protocol.NewReturnResponse(rsp, err)
|
40
|
}
|
43
|
}
|
41
|
|
44
|
|
42
|
// Voice
|
45
|
// Voice
|
|
@@ -45,25 +48,27 @@ func (this *UploadController) Voice() { |
|
@@ -45,25 +48,27 @@ func (this *UploadController) Voice() { |
45
|
var (
|
48
|
var (
|
46
|
msg *protocol.ResponseMessage
|
49
|
msg *protocol.ResponseMessage
|
47
|
err error
|
50
|
err error
|
|
|
51
|
+ rsp *protocol.FileResponse = &protocol.FileResponse{}
|
48
|
)
|
52
|
)
|
49
|
defer func() {
|
53
|
defer func() {
|
50
|
this.Resp(msg)
|
54
|
this.Resp(msg)
|
51
|
}()
|
55
|
}()
|
52
|
var request = &protocol.FileRequest{}
|
56
|
var request = &protocol.FileRequest{}
|
53
|
- //if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{
|
|
|
54
|
- // log.Error(err)
|
|
|
55
|
- // msg = protocol.ReturnResponse(1)
|
|
|
56
|
- // return
|
|
|
57
|
- //}
|
|
|
58
|
- //if b,m :=this.Valid(request);!b{
|
|
|
59
|
- // msg = m
|
|
|
60
|
- // return
|
|
|
61
|
- //}
|
|
|
62
|
- if request.Files, err = this.GetFiles("file"); err != nil {
|
|
|
63
|
- log.Error(err)
|
|
|
64
|
- return
|
57
|
+ for i := 1; i <= 9; i++ {
|
|
|
58
|
+ var tmp *protocol.FileResponse
|
|
|
59
|
+ key := fmt.Sprintf("%v%v", "voice", i)
|
|
|
60
|
+ if request.Files, err = this.GetFiles(key); err != nil {
|
|
|
61
|
+ log.Error(key, err)
|
|
|
62
|
+ err = nil
|
|
|
63
|
+ break
|
|
|
64
|
+ }
|
|
|
65
|
+ if tmp, err = upload.Voice(request); err != nil {
|
|
|
66
|
+ log.Error(err)
|
|
|
67
|
+ return
|
|
|
68
|
+ }
|
|
|
69
|
+ rsp.Paths = append(rsp.Paths, tmp.Paths...)
|
65
|
}
|
70
|
}
|
66
|
- msg = protocol.NewReturnResponse(upload.Voice(request))
|
71
|
+ msg = protocol.NewReturnResponse(rsp, err)
|
67
|
}
|
72
|
}
|
68
|
|
73
|
|
69
|
// Video
|
74
|
// Video
|
|
@@ -76,10 +81,12 @@ func (this *UploadController) Video() { |
|
@@ -76,10 +81,12 @@ func (this *UploadController) Video() { |
76
|
defer func() {
|
81
|
defer func() {
|
77
|
this.Resp(msg)
|
82
|
this.Resp(msg)
|
78
|
}()
|
83
|
}()
|
79
|
- var request = &protocol.FileRequest{}
|
|
|
80
|
- if request.Files, err = this.GetFiles("file"); err != nil {
|
|
|
81
|
- log.Error(err)
|
|
|
82
|
- return
|
84
|
+ for i := 1; i <= 9; i++ {
|
|
|
85
|
+ var request = &protocol.FileRequest{}
|
|
|
86
|
+ if request.Files, err = this.GetFiles("file"); err != nil {
|
|
|
87
|
+ log.Error(err)
|
|
|
88
|
+ return
|
|
|
89
|
+ }
|
|
|
90
|
+ msg = protocol.NewReturnResponse(upload.Video(request))
|
83
|
}
|
91
|
}
|
84
|
- msg = protocol.NewReturnResponse(upload.Video(request))
|
|
|
85
|
} |
92
|
} |