修复logo问题
This commit is contained in:
1 parent
9372a974fd
commit
7882bbbd37
6 files changed
+23
-5
No files matched your search
@@ -304,6 +304,7 @@ async fn main() -> Result<()> {
|
||||
|
||||
let app = Router::new()
|
||||
.route("/api/bootstrap", get(routes::public::bootstrap))
|
||||
.route("/api/favicon", get(routes::public::favicon))
|
||||
.route("/api/history/{id}", get(routes::public::history))
|
||||
.route("/api/latency/{id}", get(routes::public::latency_history))
|
||||
.route("/api/exchange-rates", get(routes::public::exchange_rates))
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::models::PublicConfig;
|
||||
use axum::Json;
|
||||
use axum::extract::{Path, Query, State};
|
||||
use axum::http::HeaderMap;
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use axum::response::{IntoResponse, Redirect, Response};
|
||||
use serde::Serialize;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
@@ -115,6 +115,21 @@ pub async fn bootstrap(
|
||||
}))
|
||||
}
|
||||
|
||||
pub async fn favicon(State(state): State<Arc<AppState>>) -> Result<Response, ApiResponse> {
|
||||
let settings = crate::db::load_settings(&state.db)
|
||||
.await
|
||||
.map_err(ApiResponse::internal)?;
|
||||
let logo_url = settings.logo_url.trim();
|
||||
let target = if logo_url.is_empty() {
|
||||
"/logo.svg".to_string()
|
||||
} else {
|
||||
url::Url::parse(logo_url)
|
||||
.map_err(ApiResponse::internal)?
|
||||
.to_string()
|
||||
};
|
||||
Ok(Redirect::temporary(&target).into_response())
|
||||
}
|
||||
|
||||
pub async fn history(
|
||||
State(state): State<Arc<AppState>>,
|
||||
headers: HeaderMap,
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
<meta http-equiv="Expires" content="0" />
|
||||
<meta name="theme-color" content="#f4f6f8" />
|
||||
<meta name="robots" content="noindex,nofollow" />
|
||||
<link rel="icon" href="/logo.svg" type="image/svg+xml" />
|
||||
<link rel="icon" href="/api/favicon" />
|
||||
<title>管理面板</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="theme-color" content="#edf1f3" />
|
||||
<meta name="description" content="Server status dashboard" />
|
||||
<link rel="icon" href="/logo.svg" type="image/svg+xml" />
|
||||
<link rel="icon" href="/api/favicon" />
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -94,7 +94,7 @@ export function AppProvider({ children }: { children: ReactNode }) {
|
||||
const background = resolveBackground(config.background_url, dark);
|
||||
const blur = themeToggle(config, "enableBlur");
|
||||
const carrierLatency = config.show_latency && themeToggle(config, "showCarrierLatency", false);
|
||||
useFavicon(config.logo_url);
|
||||
useFavicon(configReady ? config.logo_url : undefined);
|
||||
|
||||
if (!reloadQueueRef.current) {
|
||||
reloadQueueRef.current = createRefreshQueue(async (quiet) => {
|
||||
|
||||
@@ -32,6 +32,8 @@ export function useSystemDark() {
|
||||
|
||||
export function useFavicon(logoUrl: string | null | undefined) {
|
||||
useEffect(() => {
|
||||
// Keep the server-resolved icon while the site configuration is loading.
|
||||
if (logoUrl == null) return;
|
||||
let link = document.querySelector<HTMLLinkElement>('link[rel="icon"]');
|
||||
if (!link) {
|
||||
link = document.createElement("link");
|
||||
@@ -39,6 +41,6 @@ export function useFavicon(logoUrl: string | null | undefined) {
|
||||
document.head.append(link);
|
||||
}
|
||||
link.removeAttribute("type");
|
||||
link.href = logoUrl || "/logo.svg";
|
||||
link.href = logoUrl.trim() || "/logo.svg";
|
||||
}, [logoUrl]);
|
||||
}
|
||||
Reference in new issue
Block a user