mirror of
https://github.com/SteamDeckHomebrew/decky-loader.git
synced 2026-06-17 16:57:50 +00:00
Add support of files from data/<plugin>/ to be fetched from Front-End (#761)
* Add support of files from `data/<plugin>/assets/` to be fetched from Front-End * Add `data` regex folder into `csrf_middleware`
This commit is contained in:
@@ -23,6 +23,7 @@ csrf_token = str(uuid.uuid4())
|
|||||||
ssl_ctx = ssl.create_default_context(cafile=certifi.where())
|
ssl_ctx = ssl.create_default_context(cafile=certifi.where())
|
||||||
|
|
||||||
assets_regex = re.compile("^/plugins/.*/assets/.*")
|
assets_regex = re.compile("^/plugins/.*/assets/.*")
|
||||||
|
data_regex = re.compile("^/plugins/.*/data/.*")
|
||||||
dist_regex = re.compile("^/plugins/.*/dist/.*")
|
dist_regex = re.compile("^/plugins/.*/dist/.*")
|
||||||
frontend_regex = re.compile("^/frontend/.*")
|
frontend_regex = re.compile("^/frontend/.*")
|
||||||
logger = getLogger("Main")
|
logger = getLogger("Main")
|
||||||
@@ -45,6 +46,7 @@ async def csrf_middleware(request: Request, handler: Handler):
|
|||||||
str(request.rel_url.path) == "/fetch" or \
|
str(request.rel_url.path) == "/fetch" or \
|
||||||
str(request.rel_url.path) == "/ws" or \
|
str(request.rel_url.path) == "/ws" or \
|
||||||
assets_regex.match(str(request.rel_url)) or \
|
assets_regex.match(str(request.rel_url)) or \
|
||||||
|
data_regex.match(str(request.rel_url)) or \
|
||||||
dist_regex.match(str(request.rel_url)) or \
|
dist_regex.match(str(request.rel_url)) or \
|
||||||
frontend_regex.match(str(request.rel_url)):
|
frontend_regex.match(str(request.rel_url)):
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from typing import Any, Tuple, Dict, cast
|
|||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
|
from decky_loader.helpers import get_homebrew_path
|
||||||
from watchdog.events import RegexMatchingEventHandler, FileSystemEvent
|
from watchdog.events import RegexMatchingEventHandler, FileSystemEvent
|
||||||
from watchdog.observers import Observer
|
from watchdog.observers import Observer
|
||||||
|
|
||||||
@@ -91,6 +92,7 @@ class Loader:
|
|||||||
web.get("/plugins/{plugin_name}/frontend_bundle", self.handle_frontend_bundle),
|
web.get("/plugins/{plugin_name}/frontend_bundle", self.handle_frontend_bundle),
|
||||||
web.get("/plugins/{plugin_name}/dist/{path:.*}", self.handle_plugin_dist),
|
web.get("/plugins/{plugin_name}/dist/{path:.*}", self.handle_plugin_dist),
|
||||||
web.get("/plugins/{plugin_name}/assets/{path:.*}", self.handle_plugin_frontend_assets),
|
web.get("/plugins/{plugin_name}/assets/{path:.*}", self.handle_plugin_frontend_assets),
|
||||||
|
web.get("/plugins/{plugin_name}/data/{path:.*}", self.handle_plugin_frontend_assets_from_data),
|
||||||
])
|
])
|
||||||
|
|
||||||
server_instance.ws.add_route("loader/get_plugins", self.get_plugins)
|
server_instance.ws.add_route("loader/get_plugins", self.get_plugins)
|
||||||
@@ -142,6 +144,13 @@ class Loader:
|
|||||||
|
|
||||||
return web.FileResponse(file, headers={"Cache-Control": "no-cache"})
|
return web.FileResponse(file, headers={"Cache-Control": "no-cache"})
|
||||||
|
|
||||||
|
async def handle_plugin_frontend_assets_from_data(self, request: web.Request):
|
||||||
|
plugin = self.plugins[request.match_info["plugin_name"]]
|
||||||
|
home = get_homebrew_path()
|
||||||
|
file = path.join(home, "data", plugin.plugin_directory, request.match_info["path"])
|
||||||
|
|
||||||
|
return web.FileResponse(file, headers={"Cache-Control": "no-cache"})
|
||||||
|
|
||||||
async def handle_frontend_bundle(self, request: web.Request):
|
async def handle_frontend_bundle(self, request: web.Request):
|
||||||
plugin = self.plugins[request.match_info["plugin_name"]]
|
plugin = self.plugins[request.match_info["plugin_name"]]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user