This commit is contained in:
dni ⚡ 2022-09-22 10:46:11 +02:00
parent c32e0cbecb
commit e4c310d197
6 changed files with 43 additions and 21 deletions

View File

@ -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")

View File

@ -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'"
@ -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."""

View File

@ -12,11 +12,13 @@ wallet_class = getattr(
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

View File

@ -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")

View File

@ -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