mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-23 14:40:47 +01:00
feat: temporary fix for upgrades
This commit is contained in:
parent
11815958a3
commit
6c41ac841b
3 changed files with 23 additions and 9 deletions
|
@ -156,6 +156,14 @@ def register_new_ext_routes(app: FastAPI) -> Callable:
|
|||
def register_ext_routes(app: FastAPI, ext: Extension) -> None:
|
||||
"""Register FastAPI routes for extension."""
|
||||
ext_module = importlib.import_module(f"lnbits.extensions.{ext.code}")
|
||||
if ext.version != "":
|
||||
if f"lnbits.extensions.{ext.code}" in sys.modules:
|
||||
del sys.modules[f"lnbits.extensions.{ext.code}"]
|
||||
del ext_module
|
||||
ext_module = importlib.import_module(f"lnbits.upgrades.{ext.version}.{ext.code}-{ext.version}")
|
||||
# else:
|
||||
# ext_module = importlib.import_module(f"lnbits.extensions.{ext.code}")
|
||||
|
||||
ext_route = getattr(ext_module, f"{ext.code}_ext")
|
||||
|
||||
if hasattr(ext_module, f"{ext.code}_start"):
|
||||
|
@ -168,7 +176,11 @@ def register_ext_routes(app: FastAPI, ext: Extension) -> None:
|
|||
app.mount(s["path"], s["app"], s["name"])
|
||||
|
||||
logger.trace(f"adding route for extension {ext_module}")
|
||||
app.include_router(ext_route)
|
||||
if ext.version != "":
|
||||
# ext_route.prefix = "/sss"
|
||||
app.include_router(router=ext_route, prefix="/sss")
|
||||
else:
|
||||
app.include_router(router=ext_route)
|
||||
|
||||
|
||||
def register_startup(app: FastAPI):
|
||||
|
|
|
@ -794,16 +794,17 @@ async def api_install_extension(
|
|||
|
||||
try:
|
||||
ext_dir = os.path.join("lnbits/extensions", ext_id)
|
||||
shutil.rmtree(ext_dir, True)
|
||||
with zipfile.ZipFile(ext_zip_file, "r") as zip_ref:
|
||||
zip_ref.extractall("lnbits/extensions")
|
||||
# shutil.rmtree(ext_dir, True)
|
||||
# with zipfile.ZipFile(ext_zip_file, "r") as zip_ref:
|
||||
# zip_ref.extractall("lnbits/extensions")
|
||||
|
||||
# todo: is admin only
|
||||
ext = Extension(extension.id, True, extension.is_admin_only, extension.name)
|
||||
# lnbits/extensions/satspay/upgrade/111/satspay/__init__.py
|
||||
ext = Extension(code=extension.id, is_valid=True, is_admin_only=False, name=extension.name, version="111")
|
||||
|
||||
current_versions = await get_dbversions()
|
||||
current_version = current_versions.get(ext.code, 0)
|
||||
await migrate_extension_database(ext, current_version)
|
||||
# current_versions = await get_dbversions()
|
||||
# current_version = current_versions.get(ext.code, 0)
|
||||
# await migrate_extension_database(ext, current_version) # todo: test
|
||||
|
||||
# disable by default
|
||||
await update_user_extension(user_id=USER_ID_ALL, extension=ext_id, active=False)
|
||||
|
@ -818,7 +819,7 @@ async def api_install_extension(
|
|||
os.remove(ext_zip_file)
|
||||
|
||||
# remove module from extensions
|
||||
shutil.rmtree(ext_dir, True)
|
||||
# shutil.rmtree(ext_dir, True)
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(ex)
|
||||
)
|
||||
|
|
|
@ -25,6 +25,7 @@ class Extension(NamedTuple):
|
|||
hidden: bool = False
|
||||
migration_module: Optional[str] = None
|
||||
db_name: Optional[str] = None
|
||||
version: Optional[str] = ""
|
||||
|
||||
|
||||
class ExtensionManager:
|
||||
|
|
Loading…
Add table
Reference in a new issue