Add "https://" if instance URL misses it.

This patch adds a small function which tests for presence of either
"http://" or "https://" in the instance URL inserted by the user.

If none of them is found, it adds "https://" by default.

I noticed that somehow go-mastodon does not handle http->https redirect,
so consider this more of an hack just to not break UX.
This commit is contained in:
Gianguido Sorà 2019-05-10 20:20:51 +02:00 committed by Christian Muehlhaeuser
parent efa74679b0
commit 9eee214103

View file

@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"strings"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
@ -24,6 +25,7 @@ func connectToInstance(instance string) bool {
var authURI string
var redirectURI string
var err error
instance = addHTTPPrefixIfNeeded(instance)
tc, authURI, redirectURI, err = mastodon.RegisterAccount(instance)
if err != nil {
fmt.Println("Error registering app:", err)
@ -39,6 +41,15 @@ func connectToInstance(instance string) bool {
return true
}
// addHTTPPrefixIfNeeded adds "https://" to an instance URL where it's missing.
func addHTTPPrefixIfNeeded(instance string) string {
if !strings.HasPrefix(instance, "http://") && !strings.HasPrefix(instance, "https://") {
return "https://" + instance
}
return instance
}
func authInstance(code, redirectURI string) bool {
instance, token, clientID, clientSecret, err := tc.Authenticate(code, redirectURI)
fmt.Println("authenticate:", err)