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 = path[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
_, path, err := RepoFromPath(
|
repo, path, err := RepoFromPath(
|
||||||
username,
|
username,
|
||||||
domain,
|
domain,
|
||||||
cname,
|
cname,
|
||||||
@ -42,7 +42,7 @@ func handleSubdomain(domain string, cname string, path string, giteaClient *gite
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
serveFile(username, path, giteaClient, w)
|
serveFile(username, repo.Name, path, giteaClient, w)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Handler(pagesDomain string, giteaClient *gitea.Client) http.HandlerFunc {
|
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
|
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
|
// Provide a default
|
||||||
if path == "" {
|
if path == "" {
|
||||||
path = "/index.html"
|
path = "/index.html"
|
||||||
@ -45,9 +45,9 @@ func serveFile(username string, path string, giteaClient *gitea.Client, w http.R
|
|||||||
content = entry.(PageContentCache).Content
|
content = entry.(PageContentCache).Content
|
||||||
mimeType = entry.(PageContentCache).mimeType
|
mimeType = entry.(PageContentCache).mimeType
|
||||||
} else {
|
} else {
|
||||||
content, _, err = giteaClient.GetFile(username, "pages", PagesBranch, path, false)
|
content, _, err = giteaClient.GetFile(username, reponame, PagesBranch, path, false)
|
||||||
if err != nil {
|
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)
|
w.WriteHeader(404)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
6
repo.go
6
repo.go
@ -106,17 +106,15 @@ func RepoFromPath(username, host, cname, path string, giteaClient *gitea.Client)
|
|||||||
lookupDomain = cname
|
lookupDomain = cname
|
||||||
}
|
}
|
||||||
repoLookup, err := lookupRepoTXT(lookupDomain)
|
repoLookup, err := lookupRepoTXT(lookupDomain)
|
||||||
if err != nil || repoLookup != "" {
|
if err != nil && repoLookup != "" {
|
||||||
log.Infof(
|
log.Infof(
|
||||||
"TXT lookup for %s resulted in choosing repository %s",
|
"TXT lookup for %s resulted in choosing repository %s",
|
||||||
lookupDomain,
|
lookupDomain,
|
||||||
repoLookup,
|
repoLookup,
|
||||||
)
|
)
|
||||||
reponame = repoLookup
|
reponame = repoLookup
|
||||||
}
|
} else if (cname != "") {
|
||||||
|
|
||||||
// Allow naming the repository "example.org" (But give the TXT record preference)
|
// Allow naming the repository "example.org" (But give the TXT record preference)
|
||||||
if cname != "" && repoLookup == "" && err == nil {
|
|
||||||
reponame = cname;
|
reponame = cname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user