mirror of
https://github.com/lnbits/lnbits.git
synced 2025-04-04 18:12:02 +02:00
fix: ext upgrade (#2776)
This commit is contained in:
parent
bbae4a01c1
commit
8c5c455f1c
@ -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:
|
||||
|
@ -169,7 +169,11 @@ class Extension(BaseModel):
|
||||
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 ""
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
@ -12,19 +12,23 @@ from lnbits.core.crud import (
|
||||
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
|
||||
|
@ -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 @@ class InstalledExtensionsSettings(LNbitsSettings):
|
||||
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, "")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user