mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-25 07:07:48 +01:00
add get settings endpoint with only values you can also save
This commit is contained in:
parent
b4919fcaab
commit
b14b9f3b3a
6 changed files with 42 additions and 12 deletions
|
@ -62,10 +62,6 @@ def create_app() -> FastAPI:
|
||||||
CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"]
|
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)
|
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
||||||
|
|
||||||
register_startup(app)
|
register_startup(app)
|
||||||
|
@ -174,7 +170,7 @@ def register_assets(app: FastAPI):
|
||||||
|
|
||||||
@app.on_event("startup")
|
@app.on_event("startup")
|
||||||
async def vendored_assets_variable():
|
async def vendored_assets_variable():
|
||||||
if g().config.debug:
|
if settings.debug:
|
||||||
g().VENDORED_JS = map(url_for_vendored, get_js_vendored())
|
g().VENDORED_JS = map(url_for_vendored, get_js_vendored())
|
||||||
g().VENDORED_CSS = map(url_for_vendored, get_css_vendored())
|
g().VENDORED_CSS = map(url_for_vendored, get_css_vendored())
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -6,7 +6,7 @@ from lnbits.settings import Settings, read_only_variables
|
||||||
from lnbits.tasks import internal_invoice_queue
|
from lnbits.tasks import internal_invoice_queue
|
||||||
|
|
||||||
from . import db
|
from . import db
|
||||||
from .models import UpdateSettings
|
from .models import AdminSettings, UpdateSettings
|
||||||
|
|
||||||
|
|
||||||
async def update_wallet_balance(wallet_id: str, amount: int) -> str:
|
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)
|
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:
|
async def update_settings(data: UpdateSettings) -> Settings:
|
||||||
fields = []
|
fields = []
|
||||||
for key, value in data.dict(exclude_none=True).items():
|
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 fastapi import Query
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
@ -55,3 +55,7 @@ class UpdateSettings(BaseModel):
|
||||||
opennode_key: str = Query(None)
|
opennode_key: str = Query(None)
|
||||||
spark_url: str = Query(None)
|
spark_url: str = Query(None)
|
||||||
spark_token: str = Query(None)
|
spark_token: str = Query(None)
|
||||||
|
|
||||||
|
|
||||||
|
class AdminSettings(UpdateSettings):
|
||||||
|
lnbits_allowed_funding_sources: Optional[List[str]]
|
||||||
|
|
|
@ -314,11 +314,8 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created: function () {
|
created: function () {
|
||||||
this.settings = JSON.parse('{{ settings|tojson|safe }}') //DB data
|
this.getSettings()
|
||||||
this.balance = +'{{ balance|safe }}'
|
this.balance = +'{{ balance|safe }}'
|
||||||
this.formData = _.clone(this.settings) //model
|
|
||||||
this.updateFundingData()
|
|
||||||
console.log(this.settings)
|
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
checkChanges() {
|
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() {
|
updateSettings() {
|
||||||
let data = {
|
let data = {
|
||||||
...this.formData
|
...this.formData
|
||||||
|
|
|
@ -10,7 +10,7 @@ from lnbits.extensions.admin import admin_ext
|
||||||
from lnbits.extensions.admin.models import UpdateSettings
|
from lnbits.extensions.admin.models import UpdateSettings
|
||||||
from lnbits.server import server_restart
|
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(
|
@admin_ext.get(
|
||||||
|
@ -21,6 +21,11 @@ async def api_restart_server() -> dict[str, str]:
|
||||||
return {"status": "Success"}
|
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(
|
@admin_ext.put(
|
||||||
"/api/v1/topup/", status_code=HTTPStatus.OK, dependencies=[Depends(check_admin)]
|
"/api/v1/topup/", status_code=HTTPStatus.OK, dependencies=[Depends(check_admin)]
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import uvloop
|
import uvloop
|
||||||
|
|
||||||
uvloop.install()
|
uvloop.install()
|
||||||
|
|
||||||
import multiprocessing as mp
|
import multiprocessing as mp
|
||||||
|
|
Loading…
Add table
Reference in a new issue