Skip to content

Commit

Permalink
Add serve API to display Svelte pages created by plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Wrench56 committed Jul 8, 2024
1 parent 0b9a973 commit 956805c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/backend/api/serve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from fastapi.responses import FileResponse
import logging
import os

from utils import config, stack

_BUILD_PATH = None


async def page(path: str) -> FileResponse:
_cache_buildpath()
mname = stack.get_caller(depth=2)[0]
if not mname.startswith('plugins.plugins.'):
logging.error(f'Non-plugin called serve.page() API: "{mname}"')
return FileResponse(f'{_BUILD_PATH}/plugins')
pname = mname.split('.')[2]
fpath = f'{_BUILD_PATH}/plugins/{pname}/{path}.html'
if not os.path.exists(fpath):
logging.error(f'Plugin page "{path}" for plugin "{pname}" does not exist')
return FileResponse(f'{_BUILD_PATH}/dne.html')
return FileResponse(fpath)


def _cache_buildpath() -> None:
global _BUILD_PATH
if _BUILD_PATH is None:
_BUILD_PATH = config.fetch().get("frontend").get("build_path")

0 comments on commit 956805c

Please sign in to comment.