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