From 2b0c860335d55f6ea1b5ac8c07db549255e953da Mon Sep 17 00:00:00 2001 From: Aldino Kemal Date: Tue, 17 May 2022 17:33:52 +0700 Subject: [PATCH] feat: fix validation and update dashboard page --- src/cmd/root.go | 8 +- src/config/settings.go | 5 +- src/services/send_service_impl.go | 2 +- src/structs/send_struct.go | 6 +- src/validations/send_validation.go | 9 +- src/validations/send_validation_test.go | 21 --- src/views/index.html | 199 ++++++++++++++++++------ 7 files changed, 166 insertions(+), 84 deletions(-) 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 @@

[[ app_name ]]

Features

-
+
Login
-
App
Scan your QRCode and you can use all this API feature
@@ -40,7 +39,6 @@
Logout
-
App
Remove your login session in application
@@ -49,7 +47,6 @@
Reconnect
-
App
Reconnect to whatsapp server, please do this if your api doesn't work or your application is down or restart @@ -58,53 +55,55 @@
-
-
+
+
-
Send Message (Text) | Private Message
-
App
+
User Info
- Send any message to any whatsapp number + You can search someone user info by phone
-
+
-
Send Message (Image) | Private Message
-
App
+
User Avatar
- Send image with -
jpg/jpeg/png
- type + You can search someone avatar by phone
-
+
-
Send Message (File) | Private Message
-
App
+
User List Groups
- Send any file up to -
10MB
+ Display all groups you joined +
+
+
+
+
+
User Privacy Setting
+
+ Get your privacy settings
-
-
+
+
-
Send Message (Text) | Group
-
App
+ Private +
Send Message
Send any message to any whatsapp number
-
+
-
Send Message (Image) | Group
-
App
+ Private +
Send Image
Send image with
jpg/jpeg/png
@@ -112,52 +111,66 @@
-
+
-
Send Message (File) | Group
-
App
+ Private +
Send File
Send any file up to -
10MB
+
{{ .MaxFileSize }}
+
+
+
+
+
+ Private +
Send Video
+
+ Send video
mp4
up to +
{{ .MaxVideoSize }}
-
-
+
+
-
User Info
-
App
+ Group +
Send Message
- You can search someone user info by phone + Send any message to any whatsapp number
-
+
-
User Avatar
-
App
+ Group +
Send Image
- You can search someone avatar by phone + Send image with +
jpg/jpeg/png
+ type
-
+
-
User List Groups
-
App
+ Group +
Send File
- Display all groups you joined + Send any file up to +
{{ .MaxFileSize }}
-
+
-
User Privacy Setting
-
App
+ Group +
Send Video
- Get your privacy settings + Send video
mp4
up to +
{{ .MaxVideoSize }}
@@ -283,6 +296,37 @@
+ + +