Archived
Add complete web icon set
This commit is contained in:
1 parent
988aea8250
commit
1759415f78
5 files changed
+78
-1
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
+47
-1
@@ -519,10 +519,52 @@ def make_app(settings: DdnsSettings | None = None) -> FastAPI:
|
||||
def favicon() -> FileResponse:
|
||||
return FileResponse(ASSET_DIR / "favicon.ico", media_type="image/x-icon")
|
||||
|
||||
@app.get("/favicon-16x16.png", include_in_schema=False)
|
||||
def favicon_16_png() -> FileResponse:
|
||||
return FileResponse(ASSET_DIR / "favicon-16x16.png", media_type="image/png")
|
||||
|
||||
@app.get("/favicon-32x32.png", include_in_schema=False)
|
||||
def favicon_32_png() -> FileResponse:
|
||||
return FileResponse(ASSET_DIR / "favicon-32x32.png", media_type="image/png")
|
||||
|
||||
@app.get("/apple-touch-icon.png", include_in_schema=False)
|
||||
def apple_touch_icon_png() -> FileResponse:
|
||||
return FileResponse(ASSET_DIR / "apple-touch-icon.png", media_type="image/png")
|
||||
|
||||
@app.get("/logo.png", include_in_schema=False)
|
||||
def logo_png() -> FileResponse:
|
||||
return FileResponse(ASSET_DIR / "logo.png", media_type="image/png")
|
||||
|
||||
@app.get("/logo-192.png", include_in_schema=False)
|
||||
def logo_192_png() -> FileResponse:
|
||||
return FileResponse(ASSET_DIR / "logo-192.png", media_type="image/png")
|
||||
|
||||
@app.get("/logo-512.png", include_in_schema=False)
|
||||
def logo_512_png() -> FileResponse:
|
||||
return FileResponse(ASSET_DIR / "logo-512.png", media_type="image/png")
|
||||
|
||||
@app.get("/site.webmanifest", include_in_schema=False)
|
||||
def site_webmanifest() -> Response:
|
||||
return Response(
|
||||
"""
|
||||
{
|
||||
"name": "KarlDNS",
|
||||
"short_name": "KarlDNS",
|
||||
"description": "Accountless Dynamic DNS for routers and home labs.",
|
||||
"start_url": "/",
|
||||
"scope": "/",
|
||||
"display": "standalone",
|
||||
"background_color": "#ffffff",
|
||||
"theme_color": "#ffffff",
|
||||
"icons": [
|
||||
{"src": "/logo-192.png", "sizes": "192x192", "type": "image/png"},
|
||||
{"src": "/logo-512.png", "sizes": "512x512", "type": "image/png"}
|
||||
]
|
||||
}
|
||||
""".strip(),
|
||||
media_type="application/manifest+json",
|
||||
)
|
||||
|
||||
@app.get("/app.js", include_in_schema=False)
|
||||
def app_js() -> Response:
|
||||
return Response(APP_JS, media_type="application/javascript")
|
||||
@@ -1318,9 +1360,13 @@ def _page(title: str, body: str) -> str:
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="theme-color" content="#ffffff">
|
||||
<title>{html.escape(title)}</title>
|
||||
<link rel="icon" href="/favicon.ico" sizes="any">
|
||||
<link rel="apple-touch-icon" href="/logo.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
|
||||
<link rel="manifest" href="/site.webmanifest">
|
||||
<script src="/app.js" defer></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB" crossorigin="anonymous">
|
||||
<style>
|
||||
|
||||
@@ -609,6 +609,37 @@ def test_application_pages_use_stricter_script_csp(tmp_path: Path) -> None:
|
||||
assert client.get("/app.js").status_code == 200
|
||||
|
||||
|
||||
def test_web_icon_assets_and_manifest_are_exposed(tmp_path: Path) -> None:
|
||||
app = make_app(DdnsSettings(database_path=tmp_path / "ddns.sqlite3", admin_password="admin"))
|
||||
client = TestClient(app)
|
||||
|
||||
response = client.get("/")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert 'href="/favicon.ico"' in response.text
|
||||
assert 'href="/favicon-32x32.png"' in response.text
|
||||
assert 'href="/favicon-16x16.png"' in response.text
|
||||
assert 'href="/apple-touch-icon.png"' in response.text
|
||||
assert 'href="/site.webmanifest"' in response.text
|
||||
for path in [
|
||||
"/favicon.ico",
|
||||
"/favicon-32x32.png",
|
||||
"/favicon-16x16.png",
|
||||
"/apple-touch-icon.png",
|
||||
"/logo-192.png",
|
||||
"/logo-512.png",
|
||||
]:
|
||||
asset = client.get(path)
|
||||
assert asset.status_code == 200
|
||||
assert asset.content
|
||||
manifest = client.get("/site.webmanifest")
|
||||
assert manifest.status_code == 200
|
||||
assert manifest.json()["icons"] == [
|
||||
{"src": "/logo-192.png", "sizes": "192x192", "type": "image/png"},
|
||||
{"src": "/logo-512.png", "sizes": "512x512", "type": "image/png"},
|
||||
]
|
||||
|
||||
|
||||
def test_trusted_host_middleware_rejects_unlisted_host(tmp_path: Path) -> None:
|
||||
app = make_app(
|
||||
DdnsSettings(
|
||||
|
||||
Reference in new issue
Block a user