add get settings endpoint with only values you can also save
This commit is contained in:
parent
47c334de7a
commit
1b675f295b
|
@ -62,10 +62,6 @@ def create_app() -> FastAPI:
|
|||
CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"]
|
||||
)
|
||||
|
||||
# TODO: why those 2?
|
||||
g().config = settings
|
||||
g().base_url = f"http://{settings.host}:{settings.port}"
|
||||
|
||||
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
||||
|
||||
register_startup(app)
|
||||
|
@ -174,7 +170,7 @@ def register_assets(app: FastAPI):
|
|||
|
||||
@app.on_event("startup")
|
||||
async def vendored_assets_variable():
|
||||
if g().config.debug:
|
||||
if settings.debug:
|
||||
g().VENDORED_JS = map(url_for_vendored, get_js_vendored())
|
||||
g().VENDORED_CSS = map(url_for_vendored, get_css_vendored())
|
||||
else:
|
||||
|
|
|
@ -6,7 +6,7 @@ from lnbits.settings import Settings, read_only_variables
|
|||
from lnbits.tasks import internal_invoice_queue
|
||||
|
||||
from . import db
|
||||
from .models import UpdateSettings
|
||||
from .models import AdminSettings, UpdateSettings
|
||||
|
||||
|
||||
async def update_wallet_balance(wallet_id: str, amount: int) -> str:
|
||||
|
@ -26,6 +26,16 @@ async def update_wallet_balance(wallet_id: str, amount: int) -> str:
|
|||
await internal_invoice_queue.put(internal_id)
|
||||
|
||||
|
||||
async def get_settings() -> AdminSettings:
|
||||
row = await db.fetchone("SELECT * FROM admin.settings")
|
||||
all_settings = Settings(**row)
|
||||
settings = AdminSettings()
|
||||
for key, value in row.items():
|
||||
if hasattr(settings, key):
|
||||
setattr(settings, key, getattr(all_settings, key))
|
||||
return settings
|
||||
|
||||
|
||||
async def update_settings(data: UpdateSettings) -> Settings:
|
||||
fields = []
|
||||
for key, value in data.dict(exclude_none=True).items():
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
from fastapi import Query
|
||||
from pydantic import BaseModel
|
||||
|
@ -55,3 +55,7 @@ class UpdateSettings(BaseModel):
|
|||
opennode_key: str = Query(None)
|
||||
spark_url: str = Query(None)
|
||||
spark_token: str = Query(None)
|
||||
|
||||
|
||||
class AdminSettings(UpdateSettings):
|
||||
lnbits_allowed_funding_sources: Optional[List[str]]
|
||||
|
|
|
@ -314,11 +314,8 @@
|
|||
}
|
||||
},
|
||||
created: function () {
|
||||
this.settings = JSON.parse('{{ settings|tojson|safe }}') //DB data
|
||||
this.getSettings()
|
||||
this.balance = +'{{ balance|safe }}'
|
||||
this.formData = _.clone(this.settings) //model
|
||||
this.updateFundingData()
|
||||
console.log(this.settings)
|
||||
},
|
||||
computed: {
|
||||
checkChanges() {
|
||||
|
@ -416,6 +413,23 @@
|
|||
})
|
||||
})
|
||||
},
|
||||
getSettings() {
|
||||
LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
'/admin/api/v1/settings/?usr=' + this.g.user.id,
|
||||
this.g.user.wallets[0].adminkey
|
||||
)
|
||||
.then(response => {
|
||||
this.settings = response.data
|
||||
this.formData = _.clone(this.settings)
|
||||
this.updateFundingData()
|
||||
console.log(this.settings)
|
||||
})
|
||||
.catch(function (error) {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
},
|
||||
updateSettings() {
|
||||
let data = {
|
||||
...this.formData
|
||||
|
|
|
@ -10,7 +10,7 @@ from lnbits.extensions.admin import admin_ext
|
|||
from lnbits.extensions.admin.models import UpdateSettings
|
||||
from lnbits.server import server_restart
|
||||
|
||||
from .crud import delete_settings, update_settings, update_wallet_balance
|
||||
from .crud import delete_settings, get_settings, update_settings, update_wallet_balance
|
||||
|
||||
|
||||
@admin_ext.get(
|
||||
|
@ -21,6 +21,11 @@ async def api_restart_server() -> dict[str, str]:
|
|||
return {"status": "Success"}
|
||||
|
||||
|
||||
@admin_ext.get("/api/v1/settings/", dependencies=[Depends(check_admin)])
|
||||
async def api_get_settings() -> UpdateSettings:
|
||||
return await get_settings()
|
||||
|
||||
|
||||
@admin_ext.put(
|
||||
"/api/v1/topup/", status_code=HTTPStatus.OK, dependencies=[Depends(check_admin)]
|
||||
)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import uvloop
|
||||
|
||||
uvloop.install()
|
||||
|
||||
import multiprocessing as mp
|
||||
|
|
Loading…
Reference in New Issue
Block a user