Browse Source

fix: reconnect with basic auth

fix: remove unused code
pull/35/head
Aldino Kemal 3 years ago
parent
commit
162e72da92
  1. 9
      src/cmd/root.go
  2. 1
      src/config/settings.go
  3. 9
      src/internal/rest/helpers/common.go

9
src/cmd/root.go

@ -73,18 +73,19 @@ func runRest(_ *cobra.Command, _ []string) {
}))
if config.AppBasicAuthCredential != "" {
account := make(map[string]string, 0)
multipleBA := strings.Split(config.AppBasicAuthCredential, ",")
for _, basicAuth := range multipleBA {
ba := strings.Split(basicAuth, ":")
if len(ba) != 2 {
log.Fatalln("Basic auth is not valid, please this following format <user>:<secret>")
}
config.AppBasicAuthAccount[ba[0]] = ba[1]
account[ba[0]] = ba[1]
}
if config.AppBasicAuthAccount != nil {
if account != nil {
app.Use(basicauth.New(basicauth.Config{
Users: config.AppBasicAuthAccount,
Users: account,
}))
}
}
@ -116,7 +117,7 @@ func runRest(_ *cobra.Command, _ []string) {
go websocket.RunHub()
// Set auto reconnect to whatsapp server after booting
go helpers.SetAutoConnectAfterBooting()
go helpers.SetAutoConnectAfterBooting(appService)
if err = app.Listen(":" + config.AppPort); err != nil {
log.Fatalln("Failed to start: ", err.Error())
}

1
src/config/settings.go

@ -12,7 +12,6 @@ var (
AppOs = fmt.Sprintf("AldinoKemal")
AppPlatform = waProto.DeviceProps_PlatformType(1)
AppBasicAuthCredential string
AppBasicAuthAccount = make(map[string]string, 0)
PathQrCode = "statics/qrcode"
PathSendItems = "statics/senditems"

9
src/internal/rest/helpers/common.go

@ -1,13 +1,12 @@
package helpers
import (
"fmt"
"github.com/aldinokemal/go-whatsapp-web-multidevice/config"
"net/http"
"context"
domainApp "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/app"
"time"
)
func SetAutoConnectAfterBooting() {
func SetAutoConnectAfterBooting(service domainApp.IAppService) {
time.Sleep(2 * time.Second)
_, _ = http.Get(fmt.Sprintf("http://localhost:%s/app/reconnect", config.AppPort))
_ = service.Reconnect(context.Background())
}
Loading…
Cancel
Save