diff --git a/lnbits/app.py b/lnbits/app.py index 49ef3d1b..00ed6d8d 100644 --- a/lnbits/app.py +++ b/lnbits/app.py @@ -115,24 +115,28 @@ def create_app(config_object="lnbits.settings") -> FastAPI: return app + def check_settings(app: FastAPI): @app.on_event("startup") async def check_settings_admin(): while True: admin_set = await get_admin_settings() - if admin_set : + if admin_set: break print("Waiting for admin settings... retrying in 5 seconds!") await asyncio.sleep(5) - - admin_set.admin_users = removeEmptyString(admin_set.admin_users.split(',')) - admin_set.allowed_users = removeEmptyString(admin_set.allowed_users.split(',')) - admin_set.admin_ext = removeEmptyString(admin_set.admin_ext.split(',')) - admin_set.disabled_ext = removeEmptyString(admin_set.disabled_ext.split(',')) - admin_set.theme = removeEmptyString(admin_set.theme.split(',')) - admin_set.ad_space = removeEmptyString(admin_set.ad_space.split(',')) + + admin_set.admin_users = removeEmptyString(admin_set.admin_users.split(",")) + admin_set.allowed_users = removeEmptyString(admin_set.allowed_users.split(",")) + admin_set.admin_ext = removeEmptyString(admin_set.admin_ext.split(",")) + admin_set.disabled_ext = removeEmptyString(admin_set.disabled_ext.split(",")) + admin_set.theme = removeEmptyString(admin_set.theme.split(",")) + admin_set.ad_space = removeEmptyString(admin_set.ad_space.split(",")) g().admin_conf = conf.copy(update=admin_set.dict()) - print(f" ✔️ Access admin user account at: http://{lnbits.settings.HOST}:{lnbits.settings.PORT}/wallet?usr={admin_set.user}") + print( + f" ✔️ Access admin user account at: http://{lnbits.settings.HOST}:{lnbits.settings.PORT}/wallet?usr={admin_set.user}" + ) + def check_funding_source(app: FastAPI) -> None: @app.on_event("startup") diff --git a/lnbits/commands.py b/lnbits/commands.py index 763a5b90..86868f1f 100644 --- a/lnbits/commands.py +++ b/lnbits/commands.py @@ -5,6 +5,7 @@ import re import warnings import click +from genericpath import exists from loguru import logger from .core import db as core_db @@ -52,6 +53,7 @@ def bundle_vendored(): with open(outputpath, "w") as f: f.write(output) + async def get_admin_settings(): from lnbits.extensions.admin.models import Admin @@ -61,6 +63,7 @@ async def get_admin_settings(): return False async with ext_db.connect() as conn: + if conn.type == SQLITE: exists = await conn.fetchone( "SELECT * FROM sqlite_master WHERE type='table' AND name='admin'" @@ -69,7 +72,7 @@ async def get_admin_settings(): exists = await conn.fetchone( "SELECT * FROM information_schema.tables WHERE table_name = 'admin'" ) - + if not exists: return False @@ -77,6 +80,7 @@ async def get_admin_settings(): return Admin(**row) if row else None + async def migrate_databases(): """Creates the necessary databases if they don't exist already; or migrates them.""" diff --git a/lnbits/config.py b/lnbits/config.py index 37b700fd..cf26ad21 100644 --- a/lnbits/config.py +++ b/lnbits/config.py @@ -6,17 +6,19 @@ from typing import List, Optional from pydantic import BaseSettings, Field wallets_module = importlib.import_module("lnbits.wallets") -wallet_class = getattr( +wallet_class = getattr( wallets_module, getenv("LNBITS_BACKEND_WALLET_CLASS", "VoidWallet") ) WALLET = wallet_class() + def list_parse_fallback(v): try: return json.loads(v) except Exception as e: - return v.replace(' ','').split(',') + return v.replace(" ", "").split(",") + class Settings(BaseSettings): admin_ui: bool = Field(default=True, env="LNBITS_ADMIN_UI") @@ -24,7 +26,9 @@ class Settings(BaseSettings): admin_users: List[str] = Field(default_factory=list, env="LNBITS_ADMIN_USERS") allowed_users: List[str] = Field(default_factory=list, env="LNBITS_ALLOWED_USERS") admin_ext: List[str] = Field(default_factory=list, env="LNBITS_ADMIN_EXTENSIONS") - disabled_ext: List[str] = Field(default_factory=list, env="LNBITS_DISABLED_EXTENSIONS") + disabled_ext: List[str] = Field( + default_factory=list, env="LNBITS_DISABLED_EXTENSIONS" + ) funding_source: str = Field(default="VoidWallet", env="LNBITS_BACKEND_WALLET_CLASS") # ops data_folder: str = Field(default=None, env="LNBITS_DATA_FOLDER") @@ -37,10 +41,17 @@ class Settings(BaseSettings): denomination: str = Field(default="sats", env="LNBITS_DENOMINATION") # Change theme site_title: str = Field(default="LNbits", env="LNBITS_SITE_TITLE") - site_tagline: str = Field(default="free and open-source lightning wallet", env="LNBITS_SITE_TAGLINE") + site_tagline: str = Field( + default="free and open-source lightning wallet", env="LNBITS_SITE_TAGLINE" + ) site_description: str = Field(default=None, env="LNBITS_SITE_DESCRIPTION") - default_wallet_name: str = Field(default="LNbits wallet", env="LNBITS_DEFAULT_WALLET_NAME") - theme: List[str] = Field(default=["classic, flamingo, mint, salvador, monochrome, autumn"], env="LNBITS_THEME_OPTIONS") + default_wallet_name: str = Field( + default="LNbits wallet", env="LNBITS_DEFAULT_WALLET_NAME" + ) + theme: List[str] = Field( + default=["classic, flamingo, mint, salvador, monochrome, autumn"], + env="LNBITS_THEME_OPTIONS", + ) custom_logo: str = Field(default=None, env="LNBITS_CUSTOM_LOGO") ad_space: List[str] = Field(default_factory=list, env="LNBITS_AD_SPACE") # .env @@ -48,7 +59,7 @@ class Settings(BaseSettings): debug: Optional[str] host: Optional[str] port: Optional[str] - lnbits_path: Optional[str] = path.dirname(path.realpath(__file__)) + lnbits_path: Optional[str] = path.dirname(path.realpath(__file__)) # @validator('admin_users', 'allowed_users', 'admin_ext', 'disabled_ext', pre=True) # def validate(cls, val): diff --git a/lnbits/core/views/generic.py b/lnbits/core/views/generic.py index 83648c44..3a1fbdfc 100644 --- a/lnbits/core/views/generic.py +++ b/lnbits/core/views/generic.py @@ -39,6 +39,7 @@ from ..services import pay_invoice, redeem_lnurl_withdraw core_html_routes: APIRouter = APIRouter(tags=["Core NON-API Website Routes"]) + @core_html_routes.get("/favicon.ico", response_class=FileResponse) async def favicon(): return FileResponse("lnbits/core/static/favicon.ico") diff --git a/lnbits/decorators.py b/lnbits/decorators.py index dd26d8fe..58b025aa 100644 --- a/lnbits/decorators.py +++ b/lnbits/decorators.py @@ -235,7 +235,7 @@ async def check_user_exists(usr: UUID4) -> User: raise HTTPException( status_code=HTTPStatus.NOT_FOUND, detail="User does not exist." ) - + if LNBITS_ADMIN_UI: LNBITS_ADMIN_USERS = g().admin_conf.admin_users LNBITS_ALLOWED_USERS = g().admin_conf.allowed_users diff --git a/lnbits/helpers.py b/lnbits/helpers.py index 7bd1b54a..f4255c86 100644 --- a/lnbits/helpers.py +++ b/lnbits/helpers.py @@ -157,11 +157,13 @@ def url_for(endpoint: str, external: Optional[bool] = False, **params: Any) -> s url = f"{base}{endpoint}{url_params}" return url + def removeEmptyString(arr): return list(filter(None, arr)) + def template_renderer(additional_folders: List = []) -> Jinja2Templates: - if(settings.LNBITS_ADMIN_UI): + if settings.LNBITS_ADMIN_UI: _ = g().admin_conf settings.LNBITS_AD_SPACE = _.ad_space settings.LNBITS_HIDE_API = _.hide_api @@ -170,8 +172,8 @@ def template_renderer(additional_folders: List = []) -> Jinja2Templates: settings.LNBITS_SITE_TAGLINE = _.site_tagline settings.LNBITS_SITE_DESCRIPTION = _.site_description settings.LNBITS_THEME_OPTIONS = _.theme - settings.LNBITS_CUSTOM_LOGO = _.custom_logo - + settings.LNBITS_CUSTOM_LOGO = _.custom_logo + t = Jinja2Templates( loader=jinja2.FileSystemLoader( ["lnbits/templates", "lnbits/core/templates", *additional_folders]