mirror of
https://github.com/lnbits/lnbits.git
synced 2025-10-10 20:42:32 +02:00
feat: store and retrieved the installed_release
This commit is contained in:
@@ -6,6 +6,7 @@ from uuid import uuid4
|
|||||||
|
|
||||||
from lnbits import bolt11
|
from lnbits import bolt11
|
||||||
from lnbits.db import COCKROACH, POSTGRES, Connection
|
from lnbits.db import COCKROACH, POSTGRES, Connection
|
||||||
|
from lnbits.extension_manger import ExtensionRelease, InstallableExtension
|
||||||
from lnbits.settings import AdminSettings, EditableSettings, SuperSettings, settings
|
from lnbits.settings import AdminSettings, EditableSettings, SuperSettings, settings
|
||||||
|
|
||||||
from . import db
|
from . import db
|
||||||
@@ -74,22 +75,25 @@ async def add_installed_extension(
|
|||||||
*,
|
*,
|
||||||
ext_id: str,
|
ext_id: str,
|
||||||
version: str,
|
version: str,
|
||||||
|
name: str,
|
||||||
active: bool,
|
active: bool,
|
||||||
meta: dict,
|
meta: dict,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
await (conn or db).execute(
|
await (conn or db).execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO installed_extensions (id, version, active, meta) VALUES (?, ?, ?, ?)
|
INSERT INTO installed_extensions (id, version, name, active, meta) VALUES (?, ?, ?, ?, ?)
|
||||||
ON CONFLICT (id) DO
|
ON CONFLICT (id) DO
|
||||||
UPDATE SET (version, active, meta) = (?, ?, ?)
|
UPDATE SET (version, name, active, meta) = (?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
ext_id,
|
ext_id,
|
||||||
version,
|
version,
|
||||||
|
name,
|
||||||
active,
|
active,
|
||||||
json.dumps(meta),
|
json.dumps(meta),
|
||||||
version,
|
version,
|
||||||
|
name,
|
||||||
active,
|
active,
|
||||||
json.dumps(meta),
|
json.dumps(meta),
|
||||||
),
|
),
|
||||||
@@ -118,16 +122,22 @@ async def delete_installed_extension(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def update_user_extension(
|
async def get_installed_extension(
|
||||||
*, user_id: str, extension: str, active: bool, conn: Optional[Connection] = None
|
ext_id: str, conn: Optional[Connection] = None
|
||||||
) -> None:
|
) -> InstallableExtension:
|
||||||
await (conn or db).execute(
|
row = await (conn or db).fetchone(
|
||||||
"""
|
"SELECT * FROM installed_extensions WHERE id = ?",
|
||||||
INSERT INTO extensions ("user", extension, active) VALUES (?, ?, ?)
|
(ext_id,),
|
||||||
ON CONFLICT ("user", extension) DO UPDATE SET active = ?
|
|
||||||
""",
|
|
||||||
(user_id, extension, active, active),
|
|
||||||
)
|
)
|
||||||
|
if not row:
|
||||||
|
return None
|
||||||
|
|
||||||
|
data = dict(row)
|
||||||
|
meta = json.loads(data["meta"])
|
||||||
|
ext = InstallableExtension(**data)
|
||||||
|
if "installed_release" in meta:
|
||||||
|
ext.installed_release = ExtensionRelease(**meta["installed_release"])
|
||||||
|
return ext
|
||||||
|
|
||||||
|
|
||||||
async def get_inactive_extensions(*, conn: Optional[Connection] = None) -> List[str]:
|
async def get_inactive_extensions(*, conn: Optional[Connection] = None) -> List[str]:
|
||||||
@@ -140,6 +150,18 @@ async def get_inactive_extensions(*, conn: Optional[Connection] = None) -> List[
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def update_user_extension(
|
||||||
|
*, user_id: str, extension: str, active: bool, conn: Optional[Connection] = None
|
||||||
|
) -> None:
|
||||||
|
await (conn or db).execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO extensions ("user", extension, active) VALUES (?, ?, ?)
|
||||||
|
ON CONFLICT ("user", extension) DO UPDATE SET active = ?
|
||||||
|
""",
|
||||||
|
(user_id, extension, active, active),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# wallets
|
# wallets
|
||||||
# -------
|
# -------
|
||||||
|
|
||||||
|
@@ -277,6 +277,7 @@ async def m009_create_installed_extensions_table(db):
|
|||||||
CREATE TABLE IF NOT EXISTS installed_extensions (
|
CREATE TABLE IF NOT EXISTS installed_extensions (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
version TEXT NOT NULL,
|
version TEXT NOT NULL,
|
||||||
|
name TEXT NOT NULL,
|
||||||
active BOOLEAN DEFAULT false,
|
active BOOLEAN DEFAULT false,
|
||||||
meta TEXT NOT NULL DEFAULT '{}'
|
meta TEXT NOT NULL DEFAULT '{}'
|
||||||
);
|
);
|
||||||
|
@@ -750,6 +750,7 @@ async def api_install_extension(
|
|||||||
await add_installed_extension(
|
await add_installed_extension(
|
||||||
ext_id=data.ext_id,
|
ext_id=data.ext_id,
|
||||||
version=installed_release.version,
|
version=installed_release.version,
|
||||||
|
name=ext_info.name,
|
||||||
active=False,
|
active=False,
|
||||||
meta={"installed_release": dict(installed_release)},
|
meta={"installed_release": dict(installed_release)},
|
||||||
)
|
)
|
||||||
|
@@ -254,16 +254,17 @@ class InstallableExtension(BaseModel):
|
|||||||
shutil.rmtree(self.ext_upgrade_dir, True)
|
shutil.rmtree(self.ext_upgrade_dir, True)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def from_repo(cls, org, repository) -> Optional["InstallableExtension"]:
|
async def from_repo(
|
||||||
|
cls, ext_id, org, repository
|
||||||
|
) -> Optional["InstallableExtension"]:
|
||||||
try:
|
try:
|
||||||
|
# installed_release = await get_installed_extension(ext_id)
|
||||||
repo, latest_release, config = await fetch_github_repo_info(org, repository)
|
repo, latest_release, config = await fetch_github_repo_info(org, repository)
|
||||||
|
|
||||||
return InstallableExtension(
|
return InstallableExtension(
|
||||||
id=repo["name"],
|
id=ext_id,
|
||||||
name=config.get("name"),
|
name=config.get("name"),
|
||||||
short_description=config.get("short_description"),
|
short_description=config.get("short_description"),
|
||||||
archive="xx",
|
|
||||||
hash="123",
|
|
||||||
version="0",
|
version="0",
|
||||||
stars=repo["stargazers_count"],
|
stars=repo["stargazers_count"],
|
||||||
icon_url=icon_to_github_url(org, config.get("tile")),
|
icon_url=icon_to_github_url(org, config.get("tile")),
|
||||||
@@ -317,7 +318,7 @@ class InstallableExtension(BaseModel):
|
|||||||
if "repos" in manifest:
|
if "repos" in manifest:
|
||||||
for r in manifest["repos"]:
|
for r in manifest["repos"]:
|
||||||
ext = await InstallableExtension.from_repo(
|
ext = await InstallableExtension.from_repo(
|
||||||
r["organisation"], r["repository"]
|
r["id"], r["organisation"], r["repository"]
|
||||||
)
|
)
|
||||||
if ext:
|
if ext:
|
||||||
if ext.id in extension_id_list:
|
if ext.id in extension_id_list:
|
||||||
|
Reference in New Issue
Block a user