-
Notifications
You must be signed in to change notification settings - Fork 63
/
recording_auth.go
152 lines (127 loc) · 3.91 KB
/
recording_auth.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
package controllers
import (
"github.com/bufbuild/protovalidate-go"
"github.com/gofiber/fiber/v2"
"github.com/mynaparrot/plugnmeet-protocol/plugnmeet"
"github.com/mynaparrot/plugnmeet-protocol/utils"
"github.com/mynaparrot/plugnmeet-server/pkg/models"
"google.golang.org/protobuf/encoding/protojson"
)
func HandleFetchRecordings(c *fiber.Ctx) error {
req := new(plugnmeet.FetchRecordingsReq)
op := protojson.UnmarshalOptions{
DiscardUnknown: true,
}
err := op.Unmarshal(c.Body(), req)
if err != nil {
return utils.SendCommonProtoJsonResponse(c, false, err.Error())
}
v, err := protovalidate.New()
if err != nil {
return utils.SendCommonProtoJsonResponse(c, false, "failed to initialize validator: "+err.Error())
}
if err = v.Validate(req); err != nil {
return utils.SendCommonProtoJsonResponse(c, false, err.Error())
}
m := models.NewRecordingAuth()
result, err := m.FetchRecordings(req)
if err != nil {
return utils.SendCommonProtoJsonResponse(c, false, err.Error())
}
if result.GetTotalRecordings() == 0 {
return utils.SendCommonProtoJsonResponse(c, false, "no recordings found")
}
r := &plugnmeet.FetchRecordingsRes{
Status: true,
Msg: "success",
Result: result,
}
return utils.SendProtoJsonResponse(c, r)
}
func HandleRecordingInfo(c *fiber.Ctx) error {
req := new(plugnmeet.RecordingInfoReq)
op := protojson.UnmarshalOptions{
DiscardUnknown: true,
}
err := op.Unmarshal(c.Body(), req)
if err != nil {
return utils.SendCommonProtoJsonResponse(c, false, err.Error())
}
v, err := protovalidate.New()
if err != nil {
return utils.SendCommonProtoJsonResponse(c, false, "failed to initialize validator: "+err.Error())
}
if err = v.Validate(req); err != nil {
return utils.SendCommonProtoJsonResponse(c, false, err.Error())
}
m := models.NewRecordingAuth()
result, err := m.RecordingInfo(req)
if err != nil {
return utils.SendCommonProtoJsonResponse(c, false, err.Error())
}
return utils.SendProtoJsonResponse(c, result)
}
func HandleDeleteRecording(c *fiber.Ctx) error {
req := new(plugnmeet.DeleteRecordingReq)
op := protojson.UnmarshalOptions{
DiscardUnknown: true,
}
err := op.Unmarshal(c.Body(), req)
if err != nil {
return utils.SendCommonProtoJsonResponse(c, false, err.Error())
}
v, err := protovalidate.New()
if err != nil {
return utils.SendCommonProtoJsonResponse(c, false, "failed to initialize validator: "+err.Error())
}
if err = v.Validate(req); err != nil {
return utils.SendCommonProtoJsonResponse(c, false, err.Error())
}
m := models.NewRecordingAuth()
err = m.DeleteRecording(req)
if err != nil {
return utils.SendCommonProtoJsonResponse(c, false, err.Error())
}
return utils.SendCommonProtoJsonResponse(c, true, "success")
}
func HandleGetDownloadToken(c *fiber.Ctx) error {
req := new(plugnmeet.GetDownloadTokenReq)
op := protojson.UnmarshalOptions{
DiscardUnknown: true,
}
err := op.Unmarshal(c.Body(), req)
if err != nil {
return utils.SendCommonProtoJsonResponse(c, false, err.Error())
}
v, err := protovalidate.New()
if err != nil {
return utils.SendCommonProtoJsonResponse(c, false, "failed to initialize validator: "+err.Error())
}
if err = v.Validate(req); err != nil {
return utils.SendCommonProtoJsonResponse(c, false, err.Error())
}
m := models.NewRecordingAuth()
token, err := m.GetDownloadToken(req)
if err != nil {
return utils.SendCommonProtoJsonResponse(c, false, err.Error())
}
r := &plugnmeet.GetDownloadTokenRes{
Status: true,
Msg: "success",
Token: &token,
}
return utils.SendProtoJsonResponse(c, r)
}
func HandleDownloadRecording(c *fiber.Ctx) error {
token := c.Params("token")
if len(token) == 0 {
return c.Status(fiber.StatusUnauthorized).SendString("token require or invalid url")
}
m := models.NewRecordingAuth()
file, status, err := m.VerifyRecordingToken(token)
if err != nil {
return c.Status(status).SendString(err.Error())
}
c.Attachment(file)
return c.SendFile(file, false)
}