From c7c8b4aaa9686f223e859490f211e9fd815f4eb6 Mon Sep 17 00:00:00 2001 From: Aldino Kemal Date: Sun, 6 Nov 2022 18:36:00 +0700 Subject: [PATCH] fix: adding axios default basic auth if enabled (#23) --- src/cmd/root.go | 13 +++++++--- src/config/settings.go | 2 +- src/views/index.html | 59 ++++++++++++++++++++++++++---------------- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/cmd/root.go b/src/cmd/root.go index 8c3b64d..d66b01d 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -1,6 +1,7 @@ package cmd import ( + "encoding/base64" "fmt" "github.com/aldinokemal/go-whatsapp-web-multidevice/config" "github.com/aldinokemal/go-whatsapp-web-multidevice/controllers" @@ -51,6 +52,9 @@ func runRest(cmd *cobra.Command, args []string) { } engine := html.NewFileSystem(pkger.Dir("/views"), ".html") + engine.AddFunc("isEnableBasicAuth", func(token string) bool { + return token != "" + }) app := fiber.New(fiber.Config{ Views: engine, BodyLimit: 50 * 1024 * 1024, @@ -97,10 +101,11 @@ func runRest(cmd *cobra.Command, args []string) { app.Get("/", func(ctx *fiber.Ctx) error { 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)), + "AppHost": fmt.Sprintf("%s://%s", ctx.Protocol(), ctx.Hostname()), + "AppVersion": config.AppVersion, + "BasicAuthToken": base64.StdEncoding.EncodeToString([]byte(config.AppBasicAuthCredential)), + "MaxFileSize": humanize.Bytes(uint64(config.WhatsappSettingMaxFileSize)), + "MaxVideoSize": humanize.Bytes(uint64(config.WhatsappSettingMaxVideoSize)), }) }) diff --git a/src/config/settings.go b/src/config/settings.go index 4671306..af23098 100644 --- a/src/config/settings.go +++ b/src/config/settings.go @@ -8,7 +8,7 @@ import ( type Browser string var ( - AppVersion string = "v3.5.0" + AppVersion string = "v3.5.1" AppPort string = "3000" AppDebug bool = false AppOs string = fmt.Sprintf("AldinoKemal") diff --git a/src/views/index.html b/src/views/index.html index 86b5821..bbcf2a9 100644 --- a/src/views/index.html +++ b/src/views/index.html @@ -13,7 +13,8 @@ - + + Whatsapp Web Multi