From e2f2a1082b0a5f13e7d6c3215dce0f7bf84f8d7e Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Sun, 31 Dec 2023 22:55:37 +0100 Subject: [PATCH] Fix various bugs --- main.go | 4 ++-- pages.go | 6 +++--- repo.go | 8 +++----- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 93cb119..231f60d 100644 --- a/main.go +++ b/main.go @@ -28,7 +28,7 @@ func handleSubdomain(domain string, cname string, path string, giteaClient *gite path = path[1:] } - _, path, err := RepoFromPath( + repo, path, err := RepoFromPath( username, domain, cname, @@ -42,7 +42,7 @@ func handleSubdomain(domain string, cname string, path string, giteaClient *gite return } - serveFile(username, path, giteaClient, w) + serveFile(username, repo.Name, path, giteaClient, w) } func Handler(pagesDomain string, giteaClient *gitea.Client) http.HandlerFunc { diff --git a/pages.go b/pages.go index 6c7576c..d8ae67b 100644 --- a/pages.go +++ b/pages.go @@ -24,7 +24,7 @@ func makePageContentCacheEntry(username, path string) string { return username + ":" + path } -func serveFile(username string, path string, giteaClient *gitea.Client, w http.ResponseWriter) { +func serveFile(username, reponame, path string, giteaClient *gitea.Client, w http.ResponseWriter) { // Provide a default if path == "" { path = "/index.html" @@ -45,9 +45,9 @@ func serveFile(username string, path string, giteaClient *gitea.Client, w http.R content = entry.(PageContentCache).Content mimeType = entry.(PageContentCache).mimeType } else { - content, _, err = giteaClient.GetFile(username, "pages", PagesBranch, path, false) + content, _, err = giteaClient.GetFile(username, reponame, PagesBranch, path, false) if err != nil { - log.Errorf("Failed to get file %s (%s)", path, err) + log.Errorf("Failed to get file %s/%s/%s (%s)", username, reponame, path, err) w.WriteHeader(404) return } diff --git a/repo.go b/repo.go index 4e43b2b..05b5e32 100644 --- a/repo.go +++ b/repo.go @@ -106,17 +106,15 @@ func RepoFromPath(username, host, cname, path string, giteaClient *gitea.Client) lookupDomain = cname } repoLookup, err := lookupRepoTXT(lookupDomain) - if err != nil || repoLookup != "" { + if err != nil && repoLookup != "" { log.Infof( "TXT lookup for %s resulted in choosing repository %s", lookupDomain, repoLookup, ) reponame = repoLookup - } - - // Allow naming the repository "example.org" (But give the TXT record preference) - if cname != "" && repoLookup == "" && err == nil { + } else if (cname != "") { + // Allow naming the repository "example.org" (But give the TXT record preference) reponame = cname; }