/* This file is part of keks-meet (https://codeberg.org/metamuffin/keks-meet) which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2023 metamuffin */ #[cfg(debug_assertions)] #[macro_export] macro_rules! s_file { ($path: literal, $content_type: literal) => { warp::fs::file(concat!("../", $path)) }; } #[cfg(debug_assertions)] #[macro_export] macro_rules! s_asset_dir { ($path: literal) => { warp::fs::dir(concat!("../", $path)) }; } #[cfg(not(debug_assertions))] #[macro_export] macro_rules! s_file { ($path: literal, $content_type: literal) => { warp::any().map(|| { warp::reply::with_header( include_bytes!(concat!("../../", $path)).to_vec(), "content-type", $content_type, ) }) }; } #[cfg(not(debug_assertions))] #[macro_export] macro_rules! s_asset_dir { ($path:literal) => {{ use include_dir::{include_dir, Dir}; const DIR: Dir = include_dir!(concat!("$CARGO_MANIFEST_DIR/../", $path)); warp::path::tail().and_then(|t: warp::path::Tail| async move { let path = t.as_str(); let content_type = match &path { _ if path.ends_with(".wasm") => "application/wasm", _ if path.ends_with(".js") => "application/javascript", _ if path.ends_with(".css") => "text/css", _ if path.ends_with(".svg") => "image/svg+xml", _ if path.ends_with(".ini") => "text/plain", _ => "application/octet-stream", }; DIR.get_file(path) .map(|f| warp::reply::with_header(f.contents(), "content-type", content_type)) .ok_or(warp::reject::not_found()) }) }}; }