Add Forgejo edit/refresh sync path for space content (T05)
Keep git as source of truth: deep-link to Forgejo editor, manual refresh to drop cache, and optional signed push webhook for automatic invalidation.
This commit is contained in:
parent
9c10037f34
commit
3f30bcd340
9 changed files with 458 additions and 5 deletions
|
|
@ -189,3 +189,56 @@ _FETCH_CACHE: dict[tuple[str, str, str, str, str], FetchedFile] = {}
|
|||
|
||||
def clear_content_cache() -> None:
|
||||
_FETCH_CACHE.clear()
|
||||
|
||||
|
||||
def clear_content_cache_for_repo(owner: str, repo: str) -> int:
|
||||
"""Drop cached files for one Forgejo repo. Returns number of entries removed."""
|
||||
owner = (owner or "").strip()
|
||||
repo = (repo or "").strip()
|
||||
if not owner or not repo:
|
||||
return 0
|
||||
victims = [k for k in _FETCH_CACHE if k[0] == owner and k[1] == repo]
|
||||
for key in victims:
|
||||
del _FETCH_CACHE[key]
|
||||
return len(victims)
|
||||
|
||||
|
||||
def clear_content_cache_for_space(space: Space) -> int:
|
||||
if not space.has_content_binding:
|
||||
return 0
|
||||
return clear_content_cache_for_repo(space.forgejo_owner, space.forgejo_repo)
|
||||
|
||||
|
||||
def forgejo_repo_url(space: Space) -> str:
|
||||
base = (getattr(settings, "FORGEJO_BASE_URL", None) or "").rstrip("/")
|
||||
if not space.has_content_binding or not base:
|
||||
return ""
|
||||
return f"{base}/{space.forgejo_owner}/{space.forgejo_repo}"
|
||||
|
||||
|
||||
def forgejo_edit_url(space: Space, page: str | None = None) -> str:
|
||||
"""Deep-link to Forgejo's file editor for the page markdown (git remains SoR)."""
|
||||
base = forgejo_repo_url(space)
|
||||
if not base:
|
||||
return ""
|
||||
try:
|
||||
page_slug = normalize_page_slug(page)
|
||||
path = page_path_for(space, page_slug)
|
||||
except ContentFetchError:
|
||||
return base
|
||||
branch = space.default_branch or "main"
|
||||
# Gitea/Forgejo: /{owner}/{repo}/_edit/{branch}/{path}
|
||||
return f"{base}/_edit/{branch}/{path}"
|
||||
|
||||
|
||||
def forgejo_blob_url(space: Space, page: str | None = None) -> str:
|
||||
base = forgejo_repo_url(space)
|
||||
if not base:
|
||||
return ""
|
||||
try:
|
||||
page_slug = normalize_page_slug(page)
|
||||
path = page_path_for(space, page_slug)
|
||||
except ContentFetchError:
|
||||
return base
|
||||
branch = space.default_branch or "main"
|
||||
return f"{base}/src/branch/{branch}/{path}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue