From 70a70ca9838d7ba08fce55dcd9dde22d44302a48 Mon Sep 17 00:00:00 2001 From: Leafus Date: Sat, 14 Dec 2024 22:46:17 +0100 Subject: [PATCH] ughh --- pkg/gitea/gitea.go | 48 ++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/pkg/gitea/gitea.go b/pkg/gitea/gitea.go index 2409e13..c201924 100644 --- a/pkg/gitea/gitea.go +++ b/pkg/gitea/gitea.go @@ -162,33 +162,43 @@ func (c *Client) Open(name, ref string) (fs.File, error) { return c.serveNotFound(owner, repo), nil } + res, err := c.getRawFileOrLFS(owner, repo, filepath, ref) + if err == nil { + if strings.HasSuffix(filepath, ".md") { + res, err = handleMD(res) + if err != nil { + return nil, err + } + } + return &openFile{ + content: res, + name: filepath, + }, nil + } + + // If file not found, try as directory entries, err := c.getDirectoryContents(owner, repo, filepath, ref) if err == nil { + // Check if this is a directory and the request doesn't end with / + // If so, look for index.html in this directory + if !strings.HasSuffix(filepath, "/") { + indexContent, err := c.getRawFileOrLFS(owner, repo, filepath+"/index.html", ref) + if err == nil { + return &openFile{ + content: indexContent, + name: "index.html", + }, nil + } + } + return &openDir{ entries: entries, name: filepath, }, nil } - res, err := c.getRawFileOrLFS(owner, repo, filepath, ref) - if err != nil { - if err == fs.ErrNotExist { - return c.serveNotFound(owner, repo), nil - } - return nil, err - } - - if strings.HasSuffix(filepath, ".md") { - res, err = handleMD(res) - if err != nil { - return nil, err - } - } - - return &openFile{ - content: res, - name: filepath, - }, nil + // Neither file nor directory found + return c.serveNotFound(owner, repo), nil } func (c *Client) getRawFileOrLFS(owner, repo, filepath, ref string) ([]byte, error) {