index : sparkle-git.git

ascending towards madness

author holly sparkles <sparkles@holly.sh> 2023-12-25 12:07:55.0 +00:00:00
committer holly sparkles <sparkles@holly.sh> 2024-05-14 6:40:47.0 +00:00:00
commit
f453ce6bacc273b0244d9c03e3b7769f44510f18 [patch]
tree
7c8fe9203d2ab584768ed9f9b44f19144d35809c
parent
2a36e096acc9dce5166878d20886c431696da7da
download
f453ce6bacc273b0244d9c03e3b7769f44510f18.tar.gz

feat: add display of a custom favicon



Diff

 src/main.rs | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index c6b5ae6..dd7cfe0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -171,8 +171,16 @@ async fn main() -> Result<(), anyhow::Error> {
        .set(build_asset_hash(dark_css))
        .unwrap();

    let static_favicon = |content: &'static [u8]| {
    let static_favicon = |file: String| {
        move || async move {
            let content = std::fs::read(&PathBuf::from(&file)).unwrap_or_else(|_| {
                if !file.is_empty() {
                    warn!("Unable to load custom favicon. Loading fallback.");
                }

                include_bytes!("../statics/favicon.ico").to_vec()
            });

            let mut resp = Response::new(Body::from(content));
            resp.headers_mut().insert(
                http::header::CONTENT_TYPE,
@@ -193,6 +201,8 @@ async fn main() -> Result<(), anyhow::Error> {
        }
    };

    let config = configuration::AppConfig::load(args.config);

    let app = Router::new()
        .route("/", get(methods::index::handle))
        .route(
@@ -210,10 +220,7 @@ async fn main() -> Result<(), anyhow::Error> {
            ),
            get(static_css(dark_css)),
        )
        .route(
            "/favicon.ico",
            get(static_favicon(include_bytes!("../statics/favicon.ico"))),
        )
        .route("/favicon.ico", get(static_favicon(config.favicon.clone())))
        .route("/about", get(methods::about::handle))
        .fallback(methods::repo::service)
        .layer(TimeoutLayer::new(args.request_timeout.into()))
@@ -221,7 +228,7 @@ async fn main() -> Result<(), anyhow::Error> {
        .layer(Extension(Arc::new(Git::new(syntax_set))))
        .layer(Extension(db))
        .layer(Extension(Arc::new(args.scan_path)))
        .layer(Extension(configuration::AppConfig::load(args.config)))
        .layer(Extension(config))
        .layer(CorsLayer::new());

    let listener = TcpListener::bind(&args.bind_address).await?;