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) {
|
||||
owner, repo, filepath := splitName(name)
|
||||
|
||||
// if repo is empty they want to have the gitea-pages repo
|
||||
if repo == "" {
|
||||
repo = c.giteapages
|
||||
repo = owner + ".fluffy.pw"
|
||||
filepath = "index.html"
|
||||
}
|
||||
|
||||
// if filepath is empty they want to have the index.html
|
||||
if filepath == "" {
|
||||
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)
|
||||
if !limited && !allowall {
|
||||
// if we're checking the gitea-pages and it doesn't exist, return 404
|
||||
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
|
||||
}
|
||||
if !limited && !allowall && !isFluffyPagesRepo {
|
||||
return nil, fs.ErrNotExist
|
||||
}
|
||||
|
||||
hasConfig := true
|
||||
|
||||
if err := c.readConfig(owner, repo); err != nil {
|
||||
// we don't need a config for gitea-pages
|
||||
// no config is only exposing the gitea-pages branch
|
||||
if repo != c.giteapages && !allowall {
|
||||
if !isFluffyPagesRepo && !allowall {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
hasConfig = false
|
||||
}
|
||||
|
||||
// if we don't have a config and the repo is the gitea-pages
|
||||
// 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) {
|
||||
if !hasConfig && !validRefs(ref, allowall || isFluffyPagesRepo) {
|
||||
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) {
|
||||
if strings.HasSuffix(repo, ".fluffy.pw") {
|
||||
return true, true
|
||||
}
|
||||
|
||||
topics, err := c.repoTopics(owner, repo)
|
||||
if err != nil {
|
||||
return false, false
|
||||
|
|
Reference in a new issue