treewide: use StaticFiles() rather than rel path

This commit is not exhaustive, and it is a trend in this codebase to not
use StaticFiles() and instead use relative paths. This means the code
cannot run anywhere other than the source code directory, as it will not
find the files it is looking for
This commit is contained in:
matthewcroughan 2022-07-08 09:49:38 +01:00
parent 49bd5ad26b
commit 36e92765d3
11 changed files with 21 additions and 23 deletions

View File

@ -5,7 +5,7 @@ from starlette.requests import Request
from loguru import logger
from .commands import bundle_vendored, migrate_databases, transpile_scss
from .commands import migrate_databases
from .settings import (
DEBUG,
LNBITS_COMMIT,
@ -21,8 +21,6 @@ from .settings import (
uvloop.install()
asyncio.create_task(migrate_databases())
transpile_scss()
bundle_vendored()
from .app import create_app

View File

@ -47,9 +47,9 @@ def create_app(config_object="lnbits.settings") -> FastAPI:
configure_logger()
app = FastAPI()
app.mount("/static", StaticFiles(directory="lnbits/static"), name="static")
app.mount("/static", StaticFiles(packages=[("lnbits", "static")]), name="static")
app.mount(
"/core/static", StaticFiles(directory="lnbits/core/static"), name="core_static"
"/core/static", StaticFiles(packages=[("lnbits.core", "static")]), name="core_static"
)
origins = ["*"]

View File

@ -9,7 +9,7 @@ db = Database("ext_bleskomat")
bleskomat_static_files = [
{
"path": "/bleskomat/static",
"app": StaticFiles(directory="lnbits/extensions/bleskomat/static"),
"app": StaticFiles(packages=[("lnbits", "extensions/bleskomat/static")]),
"name": "bleskomat_static",
}
]
@ -18,7 +18,7 @@ bleskomat_ext: APIRouter = APIRouter(prefix="/bleskomat", tags=["Bleskomat"])
def bleskomat_renderer():
return template_renderer(["lnbits/extensions/bleskomat/templates"])
return template_renderer([StaticFiles(packages=[("lnbits", "extensions/bleskomat/static/templates")])])
from .lnurl_api import * # noqa

View File

@ -12,7 +12,7 @@ db = Database("ext_copilot")
copilot_static_files = [
{
"path": "/copilot/static",
"app": StaticFiles(directory="lnbits/extensions/copilot/static"),
"app": StaticFiles(packages=[("lnbits", "extensions/copilot/static")]),
"name": "copilot_static",
}
]
@ -20,7 +20,7 @@ copilot_ext: APIRouter = APIRouter(prefix="/copilot", tags=["copilot"])
def copilot_renderer():
return template_renderer(["lnbits/extensions/copilot/templates"])
return template_renderer([StaticFiles(packages=[("lnbits", "extensions/copilot/static/templates")])])
from .lnurl import * # noqa

View File

@ -9,7 +9,7 @@ db = Database("ext_discordbot")
discordbot_static_files = [
{
"path": "/discordbot/static",
"app": StaticFiles(directory="lnbits/extensions/discordbot/static"),
"app": StaticFiles(packages=[("lnbits", "extensions/discordbot/static")]),
"name": "discordbot_static",
}
]
@ -18,7 +18,7 @@ discordbot_ext: APIRouter = APIRouter(prefix="/discordbot", tags=["discordbot"])
def discordbot_renderer():
return template_renderer(["lnbits/extensions/discordbot/templates"])
return template_renderer([StaticFiles(packages=[("lnbits", "extensions/discordbot/static/templates")])])
from .views import * # noqa

View File

@ -12,7 +12,7 @@ db = Database("ext_jukebox")
jukebox_static_files = [
{
"path": "/jukebox/static",
"app": StaticFiles(directory="lnbits/extensions/jukebox/static"),
"app": StaticFiles(packages=[("lnbits", "extensions/jukebox/static")]),
"name": "jukebox_static",
}
]
@ -21,7 +21,7 @@ jukebox_ext: APIRouter = APIRouter(prefix="/jukebox", tags=["jukebox"])
def jukebox_renderer():
return template_renderer(["lnbits/extensions/jukebox/templates"])
return template_renderer([StaticFiles(packages=[("lnbits", "extensions/jukebox/static/templates")])])
from .tasks import wait_for_paid_invoices

View File

@ -12,7 +12,7 @@ db = Database("ext_livestream")
livestream_static_files = [
{
"path": "/livestream/static",
"app": StaticFiles(directory="lnbits/extensions/livestream/static"),
"app": StaticFiles(packages=[("lnbits", "extensions/livestream/static")]),
"name": "livestream_static",
}
]
@ -21,7 +21,7 @@ livestream_ext: APIRouter = APIRouter(prefix="/livestream", tags=["livestream"])
def livestream_renderer():
return template_renderer(["lnbits/extensions/livestream/templates"])
return template_renderer([StaticFiles(packages=[("lnbits", "extensions/livestream/static/templates")])])
from .lnurl import * # noqa

View File

@ -12,7 +12,7 @@ db = Database("ext_lnurlp")
lnurlp_static_files = [
{
"path": "/lnurlp/static",
"app": StaticFiles(directory="lnbits/extensions/lnurlp/static"),
"app": StaticFiles(packages=[("lnbits", "extensions/lnurlp/static")]),
"name": "lnurlp_static",
}
]
@ -21,7 +21,7 @@ lnurlp_ext: APIRouter = APIRouter(prefix="/lnurlp", tags=["lnurlp"])
def lnurlp_renderer():
return template_renderer(["lnbits/extensions/lnurlp/templates"])
return template_renderer([StaticFiles(packages=[("lnbits", "extensions/lnurlp/static/templates")])])
from .lnurl import * # noqa

View File

@ -9,7 +9,7 @@ db = Database("ext_offlineshop")
offlineshop_static_files = [
{
"path": "/offlineshop/static",
"app": StaticFiles(directory="lnbits/extensions/offlineshop/static"),
"app": StaticFiles(packages=[("lnbits", "extensions/offlineshop/static")]),
"name": "offlineshop_static",
}
]
@ -18,7 +18,7 @@ offlineshop_ext: APIRouter = APIRouter(prefix="/offlineshop", tags=["Offlineshop
def offlineshop_renderer():
return template_renderer(["lnbits/extensions/offlineshop/templates"])
return template_renderer([StaticFiles(packages=[("lnbits", "extensions/offlineshop/static/templates")])])
from .lnurl import * # noqa

View File

@ -12,7 +12,7 @@ db = Database("ext_splitpayments")
splitpayments_static_files = [
{
"path": "/splitpayments/static",
"app": StaticFiles(directory="lnbits/extensions/splitpayments/static"),
"app": StaticFiles(packages=[("lnbits", "extensions/splitpayments/static")]),
"name": "splitpayments_static",
}
]
@ -22,7 +22,7 @@ splitpayments_ext: APIRouter = APIRouter(
def splitpayments_renderer():
return template_renderer(["lnbits/extensions/splitpayments/templates"])
return template_renderer([StaticFiles(packages=[("lnbits", "extensions/splitpayments/static/templates")])])
from .tasks import wait_for_paid_invoices

View File

@ -9,7 +9,7 @@ db = Database("ext_withdraw")
withdraw_static_files = [
{
"path": "/withdraw/static",
"app": StaticFiles(directory="lnbits/extensions/withdraw/static"),
"app": StaticFiles(packages=[("lnbits", "extensions/withdraw/static")]),
"name": "withdraw_static",
}
]
@ -19,7 +19,7 @@ withdraw_ext: APIRouter = APIRouter(prefix="/withdraw", tags=["withdraw"])
def withdraw_renderer():
return template_renderer(["lnbits/extensions/withdraw/templates"])
return template_renderer([StaticFiles(packages=[("lnbits", "extensions/withdraw/static/templates")])])
from .lnurl import * # noqa