Fix serving static resources from sub-directories
This commit is contained in:
parent
c49119184d
commit
b6add700a3
@ -47,28 +47,34 @@ func (c *Client) Open(user, path string) (fs.File, error) {
|
|||||||
log.Printf("user: %s", user)
|
log.Printf("user: %s", user)
|
||||||
log.Printf("path: %s", path)
|
log.Printf("path: %s", path)
|
||||||
|
|
||||||
var repo string
|
var (
|
||||||
|
repo string
|
||||||
|
filepath string
|
||||||
|
)
|
||||||
|
|
||||||
parts := strings.Split(strings.TrimLeft(path, "/"), "/")
|
parts := strings.Split(strings.TrimLeft(path, "/"), "/")
|
||||||
log.Printf("parts: %d #%v", len(parts), parts)
|
log.Printf("parts: %d #%v", len(parts), parts)
|
||||||
if len(parts) > 1 {
|
if len(parts) > 1 {
|
||||||
repo = parts[0]
|
repo = parts[0]
|
||||||
path = strings.Join(parts[1:], "/")
|
filepath = strings.Join(parts[1:], "/")
|
||||||
} else {
|
} else {
|
||||||
repo = fmt.Sprintf("%s.%s", user, c.domain)
|
repo = fmt.Sprintf("%s.%s", user, c.domain)
|
||||||
|
filepath = path
|
||||||
}
|
}
|
||||||
log.Printf("repo: %s", repo)
|
log.Printf("repo: %s", repo)
|
||||||
|
|
||||||
// if path is empty they want to have the index.html
|
// if path is empty they want to have the index.html
|
||||||
if path == "" || path == "/" {
|
if filepath == "" || filepath == "/" {
|
||||||
path = "index.html"
|
filepath = "index.html"
|
||||||
}
|
}
|
||||||
|
|
||||||
allowed := c.allowsPages(user, repo)
|
allowed := c.allowsPages(user, repo)
|
||||||
log.Printf("allowed? %t", allowed)
|
log.Printf("allowed? %t", allowed)
|
||||||
if !allowed && repo != fmt.Sprintf("%s.%s", user, c.domain) {
|
if !allowed && repo != fmt.Sprintf("%s.%s", user, c.domain) {
|
||||||
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
|
return nil, fs.ErrNotExist
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user