ughh
This commit is contained in:
parent
c5d9235b47
commit
70a70ca983
1 changed files with 29 additions and 19 deletions
|
@ -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) {
|
||||
|
|
Reference in a new issue