This commit is contained in:
Arc
2026-05-25 14:56:04 +03:00
committed by Vlad Stan
parent f3dd667f4a
commit 46bf984c05
3 changed files with 65 additions and 23 deletions
+24 -7
View File
@@ -476,16 +476,33 @@ def register_ext_routes(app: FastAPI, ext: Extension) -> None:
def _load_extension_type(ext_id: str) -> str | None: def _load_extension_type(ext_id: str) -> str | None:
base_dirs = [
Path(settings.lnbits_extensions_path, "extensions", ext_id),
Path(settings.lnbits_extensions_path, ext_id),
Path(settings.lnbits_path, "lnbits", "extensions", ext_id),
Path(settings.lnbits_path, "extensions", ext_id),
Path.cwd() / "lnbits" / "extensions" / ext_id,
Path.cwd() / "extensions" / ext_id,
]
for base in base_dirs:
try: try:
conf_path = Path( conf_path = base / "config.json"
settings.lnbits_extensions_path, "extensions", ext_id, "config.json" if conf_path.is_file():
) with open(conf_path, "r") as json_file:
if not conf_path.is_file():
return None
with open(conf_path, "r+") as json_file:
config_json = json.load(json_file) config_json = json.load(json_file)
return config_json.get("extension_type") ext_type = config_json.get("extension_type")
if ext_type:
return ext_type
except Exception: except Exception:
continue
for base in base_dirs:
try:
wasm_dir = base / "wasm"
if (wasm_dir / "module.wasm").is_file() or (wasm_dir / "module.wat").is_file():
return "wasm"
except Exception:
continue
return None return None
+8 -1
View File
@@ -47,17 +47,24 @@ def _is_wasm_extension(ext: InstallableExtension) -> bool:
candidate_dirs = [ candidate_dirs = [
Path(ext.ext_dir), Path(ext.ext_dir),
Path(settings.lnbits_extensions_path, "extensions", ext.id), Path(settings.lnbits_extensions_path, "extensions", ext.id),
Path(settings.lnbits_extensions_path, ext.id),
Path(settings.lnbits_path, "lnbits", "extensions", ext.id),
Path(settings.lnbits_path, "extensions", ext.id), Path(settings.lnbits_path, "extensions", ext.id),
Path.cwd() / "lnbits" / "extensions" / ext.id,
Path.cwd() / "extensions" / ext.id, Path.cwd() / "extensions" / ext.id,
] ]
for base in candidate_dirs: for base in candidate_dirs:
conf_path = Path(base, "config.json") conf_path = Path(base, "config.json")
if not conf_path.is_file(): if not conf_path.is_file():
continue continue
with open(conf_path, "r+") as json_file: with open(conf_path, "r") as json_file:
config_json = json.load(json_file) config_json = json.load(json_file)
if config_json.get("extension_type") == "wasm": if config_json.get("extension_type") == "wasm":
return True return True
for base in candidate_dirs:
wasm_dir = Path(base, "wasm")
if (wasm_dir / "module.wasm").is_file() or (wasm_dir / "module.wat").is_file():
return True
except Exception as exc: except Exception as exc:
logger.debug(f"Failed to load extension config for '{ext.id}': {exc!s}") logger.debug(f"Failed to load extension config for '{ext.id}': {exc!s}")
+24 -6
View File
@@ -52,16 +52,34 @@ from lnbits.settings import settings
def _load_extension_type(ext_id: str) -> str: def _load_extension_type(ext_id: str) -> str:
base_dirs = [
Path(settings.lnbits_extensions_path, "extensions", ext_id),
Path(settings.lnbits_extensions_path, ext_id),
Path(settings.lnbits_path, "lnbits", "extensions", ext_id),
Path(settings.lnbits_path, "extensions", ext_id),
Path.cwd() / "lnbits" / "extensions" / ext_id,
Path.cwd() / "extensions" / ext_id,
]
for base in base_dirs:
try: try:
conf_path = Path( conf_path = base / "config.json"
settings.lnbits_extensions_path, "extensions", ext_id, "config.json"
)
if not conf_path.is_file(): if not conf_path.is_file():
return "python" continue
with open(conf_path, "r+") as json_file: with open(conf_path, "r") as json_file:
config_json = json.load(json_file) config_json = json.load(json_file)
return config_json.get("extension_type", "python") ext_type = config_json.get("extension_type")
if ext_type:
return ext_type
except Exception: except Exception:
continue
for base in base_dirs:
try:
wasm_dir = base / "wasm"
if (wasm_dir / "module.wasm").is_file() or (wasm_dir / "module.wat").is_file():
return "wasm"
except Exception:
continue
return "python" return "python"
from ..crud import ( from ..crud import (