feat: use hash for unique extension id
This commit is contained in:
parent
8f8ebbeeaa
commit
a6e3b5e049
|
@ -170,7 +170,7 @@ def register_ext_routes(app: FastAPI, ext: Extension) -> None:
|
|||
|
||||
logger.trace(f"adding route for extension {ext_module}")
|
||||
|
||||
prefix = f"/upgrades/{ext.version}" if ext.version != "" else ""
|
||||
prefix = f"/upgrades/{ext.hash}" if ext.hash != "" else ""
|
||||
app.include_router(router=ext_route, prefix=prefix)
|
||||
|
||||
|
||||
|
|
|
@ -794,23 +794,28 @@ 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")
|
||||
|
||||
ext_upgrade_dir = os.path.join("lnbits/upgrades", f"{extension.id}-{extension.hash}")
|
||||
os.makedirs("lnbits/upgrades", exist_ok=True)
|
||||
shutil.rmtree(ext_upgrade_dir, True)
|
||||
with zipfile.ZipFile(ext_zip_file, "r") as zip_ref:
|
||||
zip_ref.extractall(ext_upgrade_dir)
|
||||
|
||||
# todo: is admin only
|
||||
# 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",
|
||||
hash=extension.hash,
|
||||
)
|
||||
|
||||
# current_versions = await get_dbversions()
|
||||
# current_version = current_versions.get(ext.code, 0)
|
||||
# await migrate_extension_database(ext, current_version) # todo: test
|
||||
current_versions = await get_dbversions()
|
||||
current_version = current_versions.get(ext.code, 0)
|
||||
await migrate_extension_database(ext, current_version) # todo: use new module
|
||||
|
||||
# disable by default
|
||||
await update_user_extension(user_id=USER_ID_ALL, extension=ext_id, active=False)
|
||||
|
@ -826,7 +831,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)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user