From b6add700a3ce3f626171d01e366ae4289e9e5724 Mon Sep 17 00:00:00 2001 From: James Mills <1290234+prologic@users.noreply.github.com> Date: Sun, 20 Aug 2023 00:59:01 +1000 Subject: [PATCH] Fix serving static resources from sub-directories --- gitea/gitea.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/gitea/gitea.go b/gitea/gitea.go index 5551719..e6cbd8d 100644 --- a/gitea/gitea.go +++ b/gitea/gitea.go @@ -47,28 +47,34 @@ func (c *Client) Open(user, path string) (fs.File, error) { log.Printf("user: %s", user) log.Printf("path: %s", path) - var repo string + var ( + repo string + filepath string + ) parts := strings.Split(strings.TrimLeft(path, "/"), "/") log.Printf("parts: %d #%v", len(parts), parts) if len(parts) > 1 { repo = parts[0] - path = strings.Join(parts[1:], "/") + filepath = strings.Join(parts[1:], "/") } else { repo = fmt.Sprintf("%s.%s", user, c.domain) + filepath = path } log.Printf("repo: %s", repo) // if path is empty they want to have the index.html - if path == "" || path == "/" { - path = "index.html" + if filepath == "" || filepath == "/" { + filepath = "index.html" } allowed := c.allowsPages(user, repo) log.Printf("allowed? %t", allowed) if !allowed && repo != fmt.Sprintf("%s.%s", user, c.domain) { repo = fmt.Sprintf("%s.%s", user, c.domain) - if !c.allowsPages(user, repo) { + if c.allowsPages(user, repo) { + filepath = path + } else { return nil, fs.ErrNotExist } }