diff --git a/lnbits/app.py b/lnbits/app.py index 4d7b0ca8b1..67d2e181f0 100644 --- a/lnbits/app.py +++ b/lnbits/app.py @@ -226,7 +226,6 @@ async def check_installed_extensions(app: FastAPI): persist state. Zips that are missing will be re-downloaded. """ - shutil.rmtree(Path(settings.lnbits_extensions_path, "upgrades"), True) installed_extensions = await build_all_installed_extensions_list(False) for ext in installed_extensions: @@ -336,8 +335,14 @@ def register_custom_extensions_path(): + f" '{settings.lnbits_extensions_path}/extensions'" ) - sys.path.append(str(Path(settings.lnbits_extensions_path, "extensions"))) - sys.path.append(str(Path(settings.lnbits_extensions_path, "upgrades"))) + extensions_dir = Path(settings.lnbits_extensions_path, "extensions") + Path(extensions_dir).mkdir(parents=True, exist_ok=True) + sys.path.append(str(extensions_dir)) + + upgrades_dir = Path(settings.lnbits_extensions_path, "upgrades") + shutil.rmtree(upgrades_dir, True) + Path(upgrades_dir).mkdir(parents=True, exist_ok=True) + sys.path.append(str(upgrades_dir)) def register_new_ext_routes(app: FastAPI) -> Callable: diff --git a/lnbits/core/models/extensions.py b/lnbits/core/models/extensions.py index 3743e37c31..bf43ce54e4 100644 --- a/lnbits/core/models/extensions.py +++ b/lnbits/core/models/extensions.py @@ -169,7 +169,11 @@ def from_installable_ext(cls, ext_info: InstallableExtension) -> Extension: name=ext_info.name, short_description=ext_info.short_description, tile=ext_info.icon, - upgrade_hash=settings.extension_upgrade_hash(ext_info.id), + upgrade_hash=( + ext_info.hash + if settings.extension_has_been_activated(ext_info.id) + else "" + ), ) diff --git a/lnbits/core/services/extensions.py b/lnbits/core/services/extensions.py index 3d3f611a66..7e54d93b62 100644 --- a/lnbits/core/services/extensions.py +++ b/lnbits/core/services/extensions.py @@ -12,19 +12,23 @@ get_installed_extension, update_installed_extension_state, ) -from lnbits.core.crud.extensions import get_installed_extensions +from lnbits.core.crud.extensions import ( + get_installed_extensions, + update_installed_extension, +) from lnbits.core.helpers import migrate_extension_database from lnbits.settings import settings -from ..models.extensions import Extension, InstallableExtension +from ..models.extensions import Extension, ExtensionMeta, InstallableExtension async def install_extension(ext_info: InstallableExtension) -> Extension: ext_id = ext_info.id extension = Extension.from_installable_ext(ext_info) installed_ext = await get_installed_extension(ext_id) - if installed_ext: - ext_info.meta = installed_ext.meta + if installed_ext and installed_ext.meta: + ext_info.meta = ext_info.meta or ExtensionMeta() + ext_info.meta.payments = installed_ext.meta.payments await ext_info.download_archive() @@ -37,6 +41,8 @@ async def install_extension(ext_info: InstallableExtension) -> Extension: # if it does exist, it will be activated later in the code if not installed_ext: await create_installed_extension(ext_info) + else: + await update_installed_extension(ext_info) if extension.is_upgrade_extension: # call stop while the old routes are still active diff --git a/lnbits/settings.py b/lnbits/settings.py index 4c9e8e8530..12fff57418 100644 --- a/lnbits/settings.py +++ b/lnbits/settings.py @@ -126,7 +126,11 @@ class InstalledExtensionsSettings(LNbitsSettings): lnbits_extensions_redirects: list[RedirectPath] = Field(default=[]) # list of all extension ids - lnbits_all_extensions_ids: set[Any] = Field(default=[]) + lnbits_all_extensions_ids: set[str] = Field(default=[]) + + # list of all extension ids that have been activated at least once + # only add to this set, do not remove + lnbits_activated_paths_extensions_ids: set[str] = Field(default=[]) def find_extension_redirect( self, path: str, req_headers: list[tuple[bytes, bytes]] @@ -160,11 +164,15 @@ def activate_extension_paths( self._activate_extension_redirects(ext_id, ext_redirects) self.lnbits_all_extensions_ids.add(ext_id) + self.lnbits_activated_paths_extensions_ids.add(ext_id) def deactivate_extension_paths(self, ext_id: str): self.lnbits_deactivated_extensions.add(ext_id) self._remove_extension_redirects(ext_id) + def extension_has_been_activated(self, ext_id: str) -> bool: + return ext_id in settings.lnbits_activated_paths_extensions_ids + def extension_upgrade_hash(self, ext_id: str) -> str: return settings.lnbits_upgraded_extensions.get(ext_id, "")