From 884195aed4acefe3a280b4b385f9e3fc225645c5 Mon Sep 17 00:00:00 2001 From: Thomas Miceli Date: Mon, 17 Apr 2023 21:31:40 +0200 Subject: [PATCH] Trim gitea url --- internal/web/auth.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/internal/web/auth.go b/internal/web/auth.go index a396edb..d3979c5 100644 --- a/internal/web/auth.go +++ b/internal/web/auth.go @@ -179,7 +179,7 @@ func oauthCallback(ctx echo.Context) error { case "github": resp, err = http.Get("https://github.com/" + user.NickName + ".keys") case "gitea": - resp, err = http.Get("https://gitea.com/" + user.NickName + ".keys") + resp, err = http.Get(trimGiteaUrl() + "/" + user.NickName + ".keys") } if err == nil { @@ -226,12 +226,8 @@ func oauth(ctx echo.Context) error { httpProtocol = "https" } + giteaUrl := trimGiteaUrl() httpDomain := httpProtocol + "://" + ctx.Request().Host - giteaUrl := config.C.GiteaUrl - // remove trailing slash - if giteaUrl[len(giteaUrl)-1] == '/' { - giteaUrl = giteaUrl[:len(giteaUrl)-1] - } switch provider { case "github": @@ -296,3 +292,13 @@ func logout(ctx echo.Context) error { deleteCsrfCookie(ctx) return redirect(ctx, "/all") } + +func trimGiteaUrl() string { + giteaUrl := config.C.GiteaUrl + // remove trailing slash + if giteaUrl[len(giteaUrl)-1] == '/' { + giteaUrl = giteaUrl[:len(giteaUrl)-1] + } + + return giteaUrl +}