Compare commits

..

1 commit
v0.0.8 ... main

Author SHA1 Message Date
70a70ca983 ughh 2024-12-14 22:46:17 +01:00

View file

@ -162,35 +162,45 @@ func (c *Client) Open(name, ref string) (fs.File, error) {
return c.serveNotFound(owner, repo), nil return c.serveNotFound(owner, repo), nil
} }
entries, err := c.getDirectoryContents(owner, repo, filepath, ref)
if err == nil {
return &openDir{
entries: entries,
name: filepath,
}, nil
}
res, err := c.getRawFileOrLFS(owner, repo, filepath, ref) res, err := c.getRawFileOrLFS(owner, repo, filepath, ref)
if err != nil { if err == nil {
if err == fs.ErrNotExist {
return c.serveNotFound(owner, repo), nil
}
return nil, err
}
if strings.HasSuffix(filepath, ".md") { if strings.HasSuffix(filepath, ".md") {
res, err = handleMD(res) res, err = handleMD(res)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} }
return &openFile{ return &openFile{
content: res, content: res,
name: filepath, name: filepath,
}, nil }, 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
}
// Neither file nor directory found
return c.serveNotFound(owner, repo), nil
}
func (c *Client) getRawFileOrLFS(owner, repo, filepath, ref string) ([]byte, error) { func (c *Client) getRawFileOrLFS(owner, repo, filepath, ref string) ([]byte, error) {
var ( var (
giteaURL string giteaURL string