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:
|
def _load_extension_type(ext_id: str) -> str | None:
|
||||||
try:
|
base_dirs = [
|
||||||
conf_path = Path(
|
Path(settings.lnbits_extensions_path, "extensions", ext_id),
|
||||||
settings.lnbits_extensions_path, "extensions", ext_id, "config.json"
|
Path(settings.lnbits_extensions_path, ext_id),
|
||||||
)
|
Path(settings.lnbits_path, "lnbits", "extensions", ext_id),
|
||||||
if not conf_path.is_file():
|
Path(settings.lnbits_path, "extensions", ext_id),
|
||||||
return None
|
Path.cwd() / "lnbits" / "extensions" / ext_id,
|
||||||
with open(conf_path, "r+") as json_file:
|
Path.cwd() / "extensions" / ext_id,
|
||||||
config_json = json.load(json_file)
|
]
|
||||||
return config_json.get("extension_type")
|
for base in base_dirs:
|
||||||
except Exception:
|
try:
|
||||||
return None
|
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:
|
async def check_and_register_extensions(app: FastAPI) -> None:
|
||||||
|
|||||||
@@ -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}")
|
||||||
|
|
||||||
|
|||||||
@@ -52,17 +52,35 @@ from lnbits.settings import settings
|
|||||||
|
|
||||||
|
|
||||||
def _load_extension_type(ext_id: str) -> str:
|
def _load_extension_type(ext_id: str) -> str:
|
||||||
try:
|
base_dirs = [
|
||||||
conf_path = Path(
|
Path(settings.lnbits_extensions_path, "extensions", ext_id),
|
||||||
settings.lnbits_extensions_path, "extensions", ext_id, "config.json"
|
Path(settings.lnbits_extensions_path, ext_id),
|
||||||
)
|
Path(settings.lnbits_path, "lnbits", "extensions", ext_id),
|
||||||
if not conf_path.is_file():
|
Path(settings.lnbits_path, "extensions", ext_id),
|
||||||
return "python"
|
Path.cwd() / "lnbits" / "extensions" / ext_id,
|
||||||
with open(conf_path, "r+") as json_file:
|
Path.cwd() / "extensions" / ext_id,
|
||||||
config_json = json.load(json_file)
|
]
|
||||||
return config_json.get("extension_type", "python")
|
for base in base_dirs:
|
||||||
except Exception:
|
try:
|
||||||
return "python"
|
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 (
|
from ..crud import (
|
||||||
create_user_extension,
|
create_user_extension,
|
||||||
|
|||||||
Reference in New Issue
Block a user