From bd0369e45d2e88b89bf0dbdc72370f3c53d394a7 Mon Sep 17 00:00:00 2001 From: Aldino Kemal Date: Fri, 19 Apr 2024 13:59:24 +0700 Subject: [PATCH] feat: add checking ffmpeg when submit video --- src/cmd/root.go | 3 ++- src/services/send.go | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/cmd/root.go b/src/cmd/root.go index a19d2c3..1fcc79b 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -66,7 +66,8 @@ func runRest(_ *cobra.Command, _ []string) { return token != nil }) app := fiber.New(fiber.Config{ - Views: engine, + Views: engine, + BodyLimit: int(config.WhatsappSettingMaxVideoSize), }) app.Static("/statics", "./statics") app.Use("/components", filesystem.New(filesystem.Config{ diff --git a/src/services/send.go b/src/services/send.go index a62c97d..f5b1b6e 100644 --- a/src/services/send.go +++ b/src/services/send.go @@ -251,6 +251,12 @@ func (service serviceSend) SendVideo(ctx context.Context, request domainSend.Vid return response, pkgError.InternalServerError(fmt.Sprintf("failed to store video in server %v", err)) } + // Check if ffmpeg is installed + _, err = exec.LookPath("ffmpeg") + if err != nil { + return response, pkgError.InternalServerError("ffmpeg not installed") + } + // Get thumbnail video with ffmpeg thumbnailVideoPath := fmt.Sprintf("%s/%s", config.PathSendItems, generateUUID+".png") cmdThumbnail := exec.Command("ffmpeg", "-i", oriVideoPath, "-ss", "00:00:01.000", "-vframes", "1", thumbnailVideoPath) @@ -276,11 +282,6 @@ func (service serviceSend) SendVideo(ctx context.Context, request domainSend.Vid if request.Compress { compresVideoPath := fmt.Sprintf("%s/%s", config.PathSendItems, generateUUID+".mp4") - // Compress video with ffmpeg, check if ffmpeg is installed - _, err = exec.LookPath("ffmpeg") - if err != nil { - return response, pkgError.InternalServerError("ffmpeg not installed") - } cmdCompress := exec.Command("ffmpeg", "-i", oriVideoPath, "-strict", "-2", compresVideoPath) err = cmdCompress.Run()