From 6785ab90c97eca41fe747cbbc8cc1e4cb9f5c608 Mon Sep 17 00:00:00 2001 From: Leafus Date: Sat, 14 Dec 2024 22:00:50 +0100 Subject: [PATCH] Adjust for yiffing-git --- pkg/gitea/gitea.go | 42 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/pkg/gitea/gitea.go b/pkg/gitea/gitea.go index ef496e8..090332a 100644 --- a/pkg/gitea/gitea.go +++ b/pkg/gitea/gitea.go @@ -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