Fix serving static resources from sub-directories

This commit is contained in:
James Mills 2023-08-20 00:59:01 +10:00
parent c49119184d
commit b6add700a3
No known key found for this signature in database
GPG Key ID: AC4C014F1440EBD6

View File

@ -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
}
}