Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix & video size limiting #236

Merged
merged 2 commits into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/constant/config/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ const Event = "GuGoTik-Recommend"
const MsgConsumer = "GuGoTik-MgsConsumer"

const BloomRedisChannel = "GuGoTik-Bloom"

const MaxVideoSize = 200 * 1024 * 1024
2 changes: 2 additions & 0 deletions src/constant/strings/err.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ const (
FollowLimited = "关注频繁,请稍后再试!"
UserDoNotExistedCode = 10013
UserDoNotExisted = "查询用户不存在!"
OversizeVideoCode = 10014
OversizeVideo = "上传视频超过了200MB"
)
27 changes: 21 additions & 6 deletions src/services/msgconsumer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,20 @@ func saveMessage(channel *amqp.Channel) {
ctx, span := tracing.Tracer.Start(ctx, "MessageSendService")
logger := logging.LogService("MessageSend").WithContext(ctx)

// Check if it is a re-publish message
retry, ok := body.Headers["x-retry"].(int32)
if ok || retry >= 1 {
err := body.Ack(false)
if err != nil {
logger.WithFields(logrus.Fields{
"err": err,
}).Errorf("Error when dealing with the message...")
logging.SetSpanError(span, err)
}
span.End()
continue
}

if err := json.Unmarshal(body.Body, &message); err != nil {
logger.WithFields(logrus.Fields{
"from_id": message.FromUserId,
Expand Down Expand Up @@ -280,10 +294,10 @@ func saveMessage(channel *amqp.Channel) {
if err != nil {
logger.WithFields(logrus.Fields{
"err": err,
}).Errorf("Error when dealing with the message...3")
}).Errorf("Error when dealing with the message...")
logging.SetSpanError(span, err)

}
span.End()
}
}

Expand Down Expand Up @@ -369,15 +383,15 @@ func chatWithGPT(channel *amqp.Channel) {
}
logger.Infof("Successfully send the reply to user")

span.End()
err = body.Ack(false)

if err != nil {
logger.WithFields(logrus.Fields{
"err": err,
}).Errorf("Error when dealing with the message...4")
}).Errorf("Error when dealing with the message...")
logging.SetSpanError(span, err)
}
span.End()
}
}

Expand Down Expand Up @@ -470,6 +484,7 @@ func saveAuditAction(channel *amqp.Channel) {
}).Errorf("Error when dealing with the action...")
logging.SetSpanError(span, err)
}
span.End()
}
}

Expand All @@ -496,7 +511,7 @@ func errorHandler(channel *amqp.Channel, d amqp.Delivery, requeue bool, logger *
if err != nil {
logger.WithFields(logrus.Fields{
"err": err,
}).Errorf("Error when dealing with the message event...1")
}).Errorf("Error when dealing with the message event...")
}
} else {
curRetry++
Expand All @@ -508,7 +523,7 @@ func errorHandler(channel *amqp.Channel, d amqp.Delivery, requeue bool, logger *
if err != nil {
logger.WithFields(logrus.Fields{
"err": err,
}).Errorf("Error when dealing with the message event...2")
}).Errorf("Error when dealing with the message event...")
}

logger.Debugf("Retrying %d times", curRetry)
Expand Down
2 changes: 1 addition & 1 deletion src/services/publish/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func main() {
)
reg := prom.Client
reg.MustRegister(srvMetrics)
maxSize := 500 * 1024 * 1024
maxSize := config.MaxVideoSize

s := grpc.NewServer(
grpc.MaxRecvMsgSize(maxSize),
Expand Down
11 changes: 11 additions & 0 deletions src/web/publish/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ func ActionPublishHandle(c *gin.Context) {
}
}(opened)

if file.Size > config.MaxVideoSize {
logger.WithFields(logrus.Fields{
"FileSize": file.Size,
}).Errorf("Maximum file size is 200MB")
c.JSON(http.StatusOK, models.ActionPublishRes{
StatusCode: strings.OversizeVideoCode,
StatusMsg: strings.OversizeVideo,
})
return
}

var data = make([]byte, file.Size)
readSize, err := opened.Read(data)
if err != nil {
Expand Down