tweaks
This commit is contained in:
+28
-11
@@ -476,17 +476,34 @@ def register_ext_routes(app: FastAPI, ext: Extension) -> None:
|
||||
|
||||
|
||||
def _load_extension_type(ext_id: str) -> str | None:
|
||||
try:
|
||||
conf_path = Path(
|
||||
settings.lnbits_extensions_path, "extensions", ext_id, "config.json"
|
||||
)
|
||||
if not conf_path.is_file():
|
||||
return None
|
||||
with open(conf_path, "r+") as json_file:
|
||||
config_json = json.load(json_file)
|
||||
return config_json.get("extension_type")
|
||||
except Exception:
|
||||
return 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:
|
||||
conf_path = base / "config.json"
|
||||
if conf_path.is_file():
|
||||
with open(conf_path, "r") as json_file:
|
||||
config_json = json.load(json_file)
|
||||
ext_type = config_json.get("extension_type")
|
||||
if ext_type:
|
||||
return ext_type
|
||||
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
|
||||
|
||||
|
||||
async def check_and_register_extensions(app: FastAPI) -> None:
|
||||
|
||||
@@ -47,17 +47,24 @@ def _is_wasm_extension(ext: InstallableExtension) -> bool:
|
||||
candidate_dirs = [
|
||||
Path(ext.ext_dir),
|
||||
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 candidate_dirs:
|
||||
conf_path = Path(base, "config.json")
|
||||
if not conf_path.is_file():
|
||||
continue
|
||||
with open(conf_path, "r+") as json_file:
|
||||
with open(conf_path, "r") as json_file:
|
||||
config_json = json.load(json_file)
|
||||
if config_json.get("extension_type") == "wasm":
|
||||
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:
|
||||
logger.debug(f"Failed to load extension config for '{ext.id}': {exc!s}")
|
||||
|
||||
|
||||
@@ -52,17 +52,35 @@ from lnbits.settings import settings
|
||||
|
||||
|
||||
def _load_extension_type(ext_id: str) -> str:
|
||||
try:
|
||||
conf_path = Path(
|
||||
settings.lnbits_extensions_path, "extensions", ext_id, "config.json"
|
||||
)
|
||||
if not conf_path.is_file():
|
||||
return "python"
|
||||
with open(conf_path, "r+") as json_file:
|
||||
config_json = json.load(json_file)
|
||||
return config_json.get("extension_type", "python")
|
||||
except Exception:
|
||||
return "python"
|
||||
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:
|
||||
conf_path = base / "config.json"
|
||||
if not conf_path.is_file():
|
||||
continue
|
||||
with open(conf_path, "r") as json_file:
|
||||
config_json = json.load(json_file)
|
||||
ext_type = config_json.get("extension_type")
|
||||
if ext_type:
|
||||
return ext_type
|
||||
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"
|
||||
|
||||
from ..crud import (
|
||||
create_user_extension,
|
||||
|
||||
Reference in New Issue
Block a user