fix: check the settings for extension installed (#2764)

This commit is contained in:
Vlad Stan 2024-11-06 12:07:12 +02:00 committed by GitHub
parent ba5f79da2d
commit aced333c0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 7 additions and 8 deletions

View file

@ -225,7 +225,8 @@ async def check_installed_extensions(app: FastAPI):
re-created. The 'data' directory (where the '.zip' files live) is expected to re-created. The 'data' directory (where the '.zip' files live) is expected to
persist state. Zips that are missing will be re-downloaded. persist state. Zips that are missing will be re-downloaded.
""" """
shutil.rmtree(os.path.join("lnbits", "upgrades"), True)
shutil.rmtree(Path(settings.lnbits_extensions_path, "upgrades"), True)
installed_extensions = await build_all_installed_extensions_list(False) installed_extensions = await build_all_installed_extensions_list(False)
for ext in installed_extensions: for ext in installed_extensions:

View file

@ -5,7 +5,6 @@ import hashlib
import json import json
import os import os
import shutil import shutil
import sys
import zipfile import zipfile
from pathlib import Path from pathlib import Path
from typing import Any, NamedTuple, Optional from typing import Any, NamedTuple, Optional
@ -170,7 +169,7 @@ class Extension(NamedTuple):
name=ext_info.name, name=ext_info.name,
short_description=ext_info.short_description, short_description=ext_info.short_description,
tile=ext_info.icon, tile=ext_info.icon,
upgrade_hash=ext_info.hash if ext_info.module_installed else "", upgrade_hash=settings.extension_upgrade_hash(ext_info.id),
) )
@ -353,10 +352,6 @@ class InstallableExtension(BaseModel):
return f"lnbits.extensions.{self.id}" return f"lnbits.extensions.{self.id}"
return self.id return self.id
@property
def module_installed(self) -> bool:
return self.module_name in sys.modules
@property @property
def has_installed_version(self) -> bool: def has_installed_version(self) -> bool:
if not self.ext_dir.is_dir(): if not self.ext_dir.is_dir():

View file

@ -71,7 +71,7 @@ async def stop_extension_background_work(ext_id: str) -> bool:
Stop background work for extension (like asyncio.Tasks, WebSockets, etc). Stop background work for extension (like asyncio.Tasks, WebSockets, etc).
Extensions SHOULD expose a `api_stop()` function. Extensions SHOULD expose a `api_stop()` function.
""" """
upgrade_hash = settings.lnbits_upgraded_extensions.get(ext_id, "") upgrade_hash = settings.extension_upgrade_hash(ext_id)
ext = Extension(ext_id, True, upgrade_hash=upgrade_hash) ext = Extension(ext_id, True, upgrade_hash=upgrade_hash)
try: try:

View file

@ -165,6 +165,9 @@ class InstalledExtensionsSettings(LNbitsSettings):
self.lnbits_deactivated_extensions.add(ext_id) self.lnbits_deactivated_extensions.add(ext_id)
self._remove_extension_redirects(ext_id) self._remove_extension_redirects(ext_id)
def extension_upgrade_hash(self, ext_id: str) -> str:
return settings.lnbits_upgraded_extensions.get(ext_id, "")
def _activate_extension_redirects(self, ext_id: str, ext_redirects: list[dict]): def _activate_extension_redirects(self, ext_id: str, ext_redirects: list[dict]):
ext_redirect_paths = [ ext_redirect_paths = [
RedirectPath(**{"ext_id": ext_id, **er}) for er in ext_redirects RedirectPath(**{"ext_id": ext_id, **er}) for er in ext_redirects