Adjust for yiffing-git
This commit is contained in:
parent
48923386b3
commit
6785ab90c9
1 changed files with 11 additions and 31 deletions
|
@ -48,57 +48,33 @@ func NewClient(serverURL, token, giteapages, giteapagesAllowAll string) (*Client
|
||||||
func (c *Client) Open(name, ref string) (fs.File, error) {
|
func (c *Client) Open(name, ref string) (fs.File, error) {
|
||||||
owner, repo, filepath := splitName(name)
|
owner, repo, filepath := splitName(name)
|
||||||
|
|
||||||
// if repo is empty they want to have the gitea-pages repo
|
|
||||||
if repo == "" {
|
if repo == "" {
|
||||||
repo = c.giteapages
|
repo = owner + ".fluffy.pw"
|
||||||
filepath = "index.html"
|
filepath = "index.html"
|
||||||
}
|
}
|
||||||
|
|
||||||
// if filepath is empty they want to have the index.html
|
|
||||||
if filepath == "" {
|
if filepath == "" {
|
||||||
filepath = "index.html"
|
filepath = "index.html"
|
||||||
}
|
}
|
||||||
|
|
||||||
// we need to check if the repo exists (and allows access)
|
isFluffyPagesRepo := strings.HasSuffix(repo, ".fluffy.pw")
|
||||||
|
|
||||||
limited, allowall := c.allowsPages(owner, repo)
|
limited, allowall := c.allowsPages(owner, repo)
|
||||||
if !limited && !allowall {
|
if !limited && !allowall && !isFluffyPagesRepo {
|
||||||
// if we're checking the gitea-pages and it doesn't exist, return 404
|
return nil, fs.ErrNotExist
|
||||||
if repo == c.giteapages && !c.hasRepoBranch(owner, repo, c.giteapages) {
|
|
||||||
return nil, fs.ErrNotExist
|
|
||||||
}
|
|
||||||
|
|
||||||
// the repo didn't exist but maybe it's a filepath in the gitea-pages repo
|
|
||||||
// so we need to check if the gitea-pages repo exists
|
|
||||||
filepath = repo
|
|
||||||
repo = c.giteapages
|
|
||||||
|
|
||||||
if ref == "" {
|
|
||||||
ref = c.giteapages
|
|
||||||
}
|
|
||||||
|
|
||||||
limited, allowall = c.allowsPages(owner, repo)
|
|
||||||
if !limited && !allowall || !c.hasRepoBranch(owner, repo, c.giteapages) {
|
|
||||||
return nil, fs.ErrNotExist
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hasConfig := true
|
hasConfig := true
|
||||||
|
|
||||||
if err := c.readConfig(owner, repo); err != nil {
|
if err := c.readConfig(owner, repo); err != nil {
|
||||||
// we don't need a config for gitea-pages
|
if !isFluffyPagesRepo && !allowall {
|
||||||
// no config is only exposing the gitea-pages branch
|
|
||||||
if repo != c.giteapages && !allowall {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
hasConfig = false
|
hasConfig = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we don't have a config and the repo is the gitea-pages
|
if !hasConfig && !validRefs(ref, allowall || isFluffyPagesRepo) {
|
||||||
// always overwrite the ref to the gitea-pages branch
|
|
||||||
if !hasConfig && (repo == c.giteapages || ref == c.giteapages) {
|
|
||||||
ref = c.giteapages
|
|
||||||
} else if !validRefs(ref, allowall) {
|
|
||||||
return nil, fs.ErrNotExist
|
return nil, fs.ErrNotExist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,6 +183,10 @@ func (c *Client) hasRepoBranch(owner, repo, branch string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) allowsPages(owner, repo string) (bool, bool) {
|
func (c *Client) allowsPages(owner, repo string) (bool, bool) {
|
||||||
|
if strings.HasSuffix(repo, ".fluffy.pw") {
|
||||||
|
return true, true
|
||||||
|
}
|
||||||
|
|
||||||
topics, err := c.repoTopics(owner, repo)
|
topics, err := c.repoTopics(owner, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, false
|
return false, false
|
||||||
|
|
Reference in a new issue