Fix empty response on first request

This commit is contained in:
PapaTutuWawa 2023-12-31 14:08:23 +01:00
parent cbb79c6d33
commit 470d759797

View File

@ -39,12 +39,13 @@ func serveFile(username string, path string, giteaClient *gitea.Client, w http.R
entry, found := pageCache.Get(key)
var content []byte
var mimeType string
var err error
if found {
log.Debugf("Returning %s from cache", path)
content = entry.(PageContentCache).Content
mimeType = entry.(PageContentCache).mimeType
} else {
content, _, err := giteaClient.GetFile(username, "pages", PagesBranch, path, false)
content, _, err = giteaClient.GetFile(username, "pages", PagesBranch, path, false)
if err != nil {
log.Errorf("Failed to get file %s (%s)", path, err)
w.WriteHeader(404)
@ -53,7 +54,7 @@ func serveFile(username string, path string, giteaClient *gitea.Client, w http.R
pathParts := strings.Split(path, ".")
ext := pathParts[len(pathParts) - 1]
mimeType := mime.TypeByExtension("." + ext)
mimeType = mime.TypeByExtension("." + ext)
pageCache.Set(
key,
@ -63,6 +64,8 @@ func serveFile(username string, path string, giteaClient *gitea.Client, w http.R
},
cache.DefaultExpiration,
)
log.Debugf("Page %s requested from Gitea and cached in memory", path)
}
w.WriteHeader(200)