Fix various bugs
This commit is contained in:
parent
da30ec9fa6
commit
e2f2a1082b
4
main.go
4
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 {
|
||||
|
6
pages.go
6
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
|
||||
}
|
||||
|
6
repo.go
6
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
|
||||
}
|
||||
|
||||
} else if (cname != "") {
|
||||
// Allow naming the repository "example.org" (But give the TXT record preference)
|
||||
if cname != "" && repoLookup == "" && err == nil {
|
||||
reponame = cname;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user