-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
serve
API to display Svelte pages created by plugins
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |