From 73da80adc1b61712407a9f9d116300cbdf0f686f Mon Sep 17 00:00:00 2001 From: fnetx Date: Fri, 26 Nov 2021 17:10:31 +0100 Subject: [PATCH] Switch GiteaApiToken from byte to string --- domains.go | 2 +- handler.go | 6 +++--- main.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/domains.go b/domains.go index 0699f0f..0a5abc1 100644 --- a/domains.go +++ b/domains.go @@ -81,7 +81,7 @@ func checkCanonicalDomain(targetOwner, targetRepo, targetBranch, actualDomain st } } else { req := fasthttp.AcquireRequest() - req.SetRequestURI(string(GiteaRoot) + "/api/v1/repos/" + targetOwner + "/" + targetRepo + "/raw/" + targetBranch + "/.domains" + "?access_token=" + string(GiteaApiToken)) + req.SetRequestURI(string(GiteaRoot) + "/api/v1/repos/" + targetOwner + "/" + targetRepo + "/raw/" + targetBranch + "/.domains" + "?access_token=" + GiteaApiToken) res := fasthttp.AcquireResponse() err := upstreamClient.Do(req, res) diff --git a/handler.go b/handler.go index af6497d..720ccde 100644 --- a/handler.go +++ b/handler.go @@ -345,7 +345,7 @@ func getBranchTimestamp(owner, repo, branch string) *branchTimestamp { if branch == "" { // Get default branch var body = make([]byte, 0) - status, body, err := fasthttp.GetTimeout(body, string(GiteaRoot)+"/api/v1/repos/"+owner+"/"+repo+"?access_token="+string(GiteaApiToken), 5*time.Second) + status, body, err := fasthttp.GetTimeout(body, string(GiteaRoot)+"/api/v1/repos/"+owner+"/"+repo+"?access_token="+GiteaApiToken, 5*time.Second) if err != nil || status != 200 { _ = branchTimestampCache.Set(owner+"/"+repo+"/"+branch, nil, DefaultBranchCacheTimeout) return nil @@ -354,7 +354,7 @@ func getBranchTimestamp(owner, repo, branch string) *branchTimestamp { } var body = make([]byte, 0) - status, body, err := fasthttp.GetTimeout(body, string(GiteaRoot)+"/api/v1/repos/"+owner+"/"+repo+"/branches/"+branch+"?access_token="+string(GiteaApiToken), 5*time.Second) + status, body, err := fasthttp.GetTimeout(body, string(GiteaRoot)+"/api/v1/repos/"+owner+"/"+repo+"/branches/"+branch+"?access_token="+GiteaApiToken, 5*time.Second) if err != nil || status != 200 { return nil } @@ -416,7 +416,7 @@ func upstream(ctx *fasthttp.RequestCtx, targetOwner string, targetRepo string, t cachedResponse = cachedValue.(fileResponse) } else { req = fasthttp.AcquireRequest() - req.SetRequestURI(string(GiteaRoot) + "/api/v1/repos/" + uri + "?access_token=" + string(GiteaApiToken)) + req.SetRequestURI(string(GiteaRoot) + "/api/v1/repos/" + uri + "?access_token=" + GiteaApiToken) res = fasthttp.AcquireResponse() res.SetBodyStream(&strings.Reader{}, -1) err = upstreamClient.Do(req, res) diff --git a/main.go b/main.go index 331a81c..1d73e33 100644 --- a/main.go +++ b/main.go @@ -39,7 +39,7 @@ var MainDomainSuffix = []byte("." + envOr("PAGES_DOMAIN", "codeberg.page")) // GiteaRoot specifies the root URL of the Gitea instance, without a trailing slash. var GiteaRoot = []byte(envOr("GITEA_ROOT", "https://codeberg.org")) -var GiteaApiToken = []byte(envOr("GITEA_API_TOKEN", "")) +var GiteaApiToken = envOr("GITEA_API_TOKEN", "") //go:embed 404.html var NotFoundPage []byte