diff --git a/src/cmd/root.go b/src/cmd/root.go index f4d9717..cf73dbe 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -7,6 +7,7 @@ import ( "github.com/aldinokemal/go-whatsapp-web-multidevice/middleware" "github.com/aldinokemal/go-whatsapp-web-multidevice/services" "github.com/aldinokemal/go-whatsapp-web-multidevice/utils" + "github.com/dustin/go-humanize" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/cors" "github.com/gofiber/fiber/v2/middleware/logger" @@ -79,7 +80,12 @@ func runRest(cmd *cobra.Command, args []string) { userController.Route(app) app.Get("/", func(ctx *fiber.Ctx) error { - return ctx.Render("index", fiber.Map{"AppHost": fmt.Sprintf("%s://%s", ctx.Protocol(), ctx.Hostname())}) + return ctx.Render("index", fiber.Map{ + "AppHost": fmt.Sprintf("%s://%s", ctx.Protocol(), ctx.Hostname()), + "AppVersion": config.AppVersion, + "MaxFileSize": humanize.Bytes(uint64(config.WhatsappSettingMaxFileSize)), + "MaxVideoSize": humanize.Bytes(uint64(config.WhatsappSettingMaxVideoSize)), + }) }) err = app.Listen(":" + config.AppPort) diff --git a/src/config/settings.go b/src/config/settings.go index b78f726..6956e2d 100644 --- a/src/config/settings.go +++ b/src/config/settings.go @@ -3,8 +3,9 @@ package config type Browser string var ( - AppPort string = "3000" - AppDebug bool = false + AppVersion string = "3.3.0" + AppPort string = "3000" + AppDebug bool = false PathQrCode string = "statics/qrcode" PathSendItems string = "statics/senditems" diff --git a/src/services/send_service_impl.go b/src/services/send_service_impl.go index 8ee73b9..58f50dd 100644 --- a/src/services/send_service_impl.go +++ b/src/services/send_service_impl.go @@ -185,7 +185,7 @@ func (service SendServiceImpl) SendVideo(c *fiber.Ctx, request structs.SendVideo // Resize Thumbnail openImageBuffer, err := bimg.Read(thumbnailVideoPath) - resize, err := bimg.NewImage(openImageBuffer).Thumbnail(100) + resize, err := bimg.NewImage(openImageBuffer).Process(bimg.Options{Quality: 90, Width: 600, Embed: true}) if err != nil { return response, err } diff --git a/src/structs/send_struct.go b/src/structs/send_struct.go index a54dc23..3ddd2a1 100644 --- a/src/structs/send_struct.go +++ b/src/structs/send_struct.go @@ -24,7 +24,7 @@ type SendImageRequest struct { Caption string `json:"caption" form:"caption"` Image *multipart.FileHeader `json:"image" form:"image"` ViewOnce bool `json:"view_once" form:"view_once"` - Type SendType `json:"type" form:"message"` + Type SendType `json:"type" form:"type"` } type SendImageResponse struct { @@ -34,7 +34,7 @@ type SendImageResponse struct { type SendFileRequest struct { Phone string `json:"phone" form:"phone"` File *multipart.FileHeader `json:"file" form:"file"` - Type SendType `json:"type" form:"message"` + Type SendType `json:"type" form:"type"` } type SendFileResponse struct { @@ -45,7 +45,7 @@ type SendVideoRequest struct { Phone string `json:"phone" form:"phone"` Caption string `json:"caption" form:"caption"` Video *multipart.FileHeader `json:"video" form:"video"` - Type SendType `json:"type" form:"message"` + Type SendType `json:"type" form:"type"` ViewOnce bool `json:"view_once" form:"view_once"` Compress bool `json:"compress"` } diff --git a/src/validations/send_validation.go b/src/validations/send_validation.go index 6e35d94..d479fce 100644 --- a/src/validations/send_validation.go +++ b/src/validations/send_validation.go @@ -7,12 +7,11 @@ import ( "github.com/aldinokemal/go-whatsapp-web-multidevice/utils" "github.com/dustin/go-humanize" validation "github.com/go-ozzo/ozzo-validation/v4" - "github.com/go-ozzo/ozzo-validation/v4/is" ) func ValidateSendMessage(request structs.SendMessageRequest) { err := validation.ValidateStruct(&request, - validation.Field(&request.Phone, validation.Required, is.Digit, validation.Length(10, 25)), + validation.Field(&request.Phone, validation.Required, validation.Length(10, 25)), validation.Field(&request.Message, validation.Required, validation.Length(1, 50)), ) @@ -25,7 +24,7 @@ func ValidateSendMessage(request structs.SendMessageRequest) { func ValidateSendImage(request structs.SendImageRequest) { err := validation.ValidateStruct(&request, - validation.Field(&request.Phone, validation.Required, is.Digit, validation.Length(10, 25)), + validation.Field(&request.Phone, validation.Required, validation.Length(10, 25)), validation.Field(&request.Caption, validation.When(true, validation.Length(1, 200))), validation.Field(&request.Image, validation.Required), ) @@ -51,7 +50,7 @@ func ValidateSendImage(request structs.SendImageRequest) { func ValidateSendFile(request structs.SendFileRequest) { err := validation.ValidateStruct(&request, - validation.Field(&request.Phone, validation.Required, is.Digit, validation.Length(10, 25)), + validation.Field(&request.Phone, validation.Required, validation.Length(10, 25)), validation.Field(&request.File, validation.Required), ) @@ -71,7 +70,7 @@ func ValidateSendFile(request structs.SendFileRequest) { func ValidateSendVideo(request structs.SendVideoRequest) { err := validation.ValidateStruct(&request, - validation.Field(&request.Phone, validation.Required, is.Digit, validation.Length(10, 25)), + validation.Field(&request.Phone, validation.Required, validation.Length(10, 25)), validation.Field(&request.Video, validation.Required), ) diff --git a/src/validations/send_validation_test.go b/src/validations/send_validation_test.go index 57d31bf..b4ff7d7 100644 --- a/src/validations/send_validation_test.go +++ b/src/validations/send_validation_test.go @@ -2,7 +2,6 @@ package validations import ( "github.com/aldinokemal/go-whatsapp-web-multidevice/structs" - "github.com/aldinokemal/go-whatsapp-web-multidevice/utils" "github.com/stretchr/testify/assert" "testing" ) @@ -24,26 +23,6 @@ func TestValidateSendMessage(t *testing.T) { }}, err: nil, }, - { - name: "error invalid phone", - args: args{request: structs.SendMessageRequest{ - Phone: "some-random-phone", - Message: "Hello this is testing", - }}, - err: utils.ValidationError{ - Message: "phone: must contain digits only.", - }, - }, - { - name: "error invalid phone contains dash (-)", - args: args{request: structs.SendMessageRequest{ - Phone: "6289-748-291", - Message: "Hello this is testing", - }}, - err: utils.ValidationError{ - Message: "phone: must contain digits only.", - }, - }, } for _, tt := range tests { diff --git a/src/views/index.html b/src/views/index.html index 9ea83ea..080add7 100644 --- a/src/views/index.html +++ b/src/views/index.html @@ -27,11 +27,10 @@