fix: upgrade vs install

This commit is contained in:
Vlad Stan 2023-01-25 14:32:41 +02:00
parent a242a823fc
commit 46faa62b8b
3 changed files with 7 additions and 8 deletions

View file

@ -211,7 +211,7 @@ def register_ext_routes(app: FastAPI, ext: Extension) -> None:
logger.trace(f"adding route for extension {ext_module}") logger.trace(f"adding route for extension {ext_module}")
prefix = f"/upgrades/{ext.hash}" if ext.hash != "" else "" prefix = f"/upgrades/{ext.upgrade_hash}" if ext.upgrade_hash != "" else ""
app.include_router(router=ext_route, prefix=prefix) app.include_router(router=ext_route, prefix=prefix)

View file

@ -756,14 +756,15 @@ async def api_install_extension(
# mount routes for the new version # mount routes for the new version
core_app_extra.register_new_ext_routes(extension) core_app_extra.register_new_ext_routes(extension)
if ext_info.module_installed: if extension.upgrade_hash:
ext_info.nofiy_upgrade() ext_info.nofiy_upgrade()
except Exception as ex: except Exception as ex:
logger.warning(ex) logger.warning(ex)
ext_info.clean_extension_files() ext_info.clean_extension_files()
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail="Failed to install extension." status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
detail="Failed to install extension.",
) )

View file

@ -30,13 +30,13 @@ class Extension(NamedTuple):
hidden: bool = False hidden: bool = False
migration_module: Optional[str] = None migration_module: Optional[str] = None
db_name: Optional[str] = None db_name: Optional[str] = None
hash: Optional[str] = "" upgrade_hash: Optional[str] = ""
@property @property
def module_name(self): def module_name(self):
return ( return (
f"lnbits.extensions.{self.code}" f"lnbits.extensions.{self.code}"
if self.hash == "" if self.upgrade_hash == ""
else f"lnbits.upgrades.{self.code}-{self.hash}.{self.code}" else f"lnbits.upgrades.{self.code}-{self.hash}.{self.code}"
) )
@ -47,7 +47,7 @@ class Extension(NamedTuple):
is_valid=True, is_valid=True,
is_admin_only=False, # todo: is admin only is_admin_only=False, # todo: is admin only
name=ext_info.name, name=ext_info.name,
hash=ext_info.hash if ext_info.module_installed else "", upgrade_hash=ext_info.hash if ext_info.module_installed else "",
) )
@ -301,8 +301,6 @@ class InstallableExtension(BaseModel):
def nofiy_upgrade(self) -> None: def nofiy_upgrade(self) -> None:
"""Update the list of upgraded extensions. The middleware will perform redirects based on this""" """Update the list of upgraded extensions. The middleware will perform redirects based on this"""
if not self.hash:
return
clean_upgraded_exts = list( clean_upgraded_exts = list(
filter( filter(