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
|
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)
|
entries, err := c.getDirectoryContents(owner, repo, filepath, ref)
|
||||||
if err == nil {
|
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{
|
return &openDir{
|
||||||
entries: entries,
|
entries: entries,
|
||||||
name: filepath,
|
name: filepath,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := c.getRawFileOrLFS(owner, repo, filepath, ref)
|
// Neither file nor directory found
|
||||||
if err != nil {
|
return c.serveNotFound(owner, repo), 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) getRawFileOrLFS(owner, repo, filepath, ref string) ([]byte, error) {
|
func (c *Client) getRawFileOrLFS(owner, repo, filepath, ref string) ([]byte, error) {
|
||||||
|
|
Reference in a new issue