me-site/src/pages/assets.rs

72 lines
2.3 KiB
Rust
Raw Normal View History

2022-11-12 00:41:51 +01:00
use actix_files::NamedFile;
use actix_web::*;
use std::io::Write;
// Bootstrap
async fn download_file(url: &str, file: &str) {
let content = reqwest::get(url).await.expect("couldn't download file");
std::fs::File::create(file)
.unwrap()
.write_all(&content.bytes().await.unwrap())
.unwrap();
}
pub(crate) async fn cache_bootstrap() {
std::fs::create_dir_all("./cache/fonts").expect("couldn't create cache dir");
download_file(
"https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css",
"./cache/bootstrap.min.css",
)
.await;
download_file(
"https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/bootstrap-icons.css",
"./cache/bootstrap-icons.css",
)
.await;
download_file(
"https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js",
"./cache/bootstrap.bundle.min.js",
)
.await;
download_file("https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/fonts/bootstrap-icons.woff2?8d200481aa7f02a2d63a331fc782cfaf", "./cache/fonts/bootstrap-icons.woff2").await;
download_file("https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/fonts/bootstrap-icons.woff?8d200481aa7f02a2d63a331fc782cfaf", "./cache/fonts/bootstrap-icons.woff").await;
}
#[get("/bootstrap.min.css")]
pub(crate) async fn bootstrap_css() -> Result<NamedFile> {
Ok(NamedFile::open("./cache/bootstrap.min.css")?)
}
#[get("/bootstrap-icons.css")]
pub(crate) async fn bootstrap_icons() -> Result<NamedFile> {
Ok(NamedFile::open("./cache/bootstrap-icons.css")?)
}
#[get("/bootstrap.bundle.min.js")]
pub(crate) async fn bootstrap_js() -> Result<NamedFile> {
Ok(NamedFile::open("./cache/bootstrap.bundle.min.js")?)
}
#[get("/fonts/bootstrap-icons.woff2")]
pub(crate) async fn bootstrap_font1(_: HttpRequest) -> Result<NamedFile> {
Ok(NamedFile::open("./cache/fonts/bootstrap-icons.woff2")?)
}
#[get("/fonts/bootstrap-icons.woff")]
pub(crate) async fn bootstrap_font2(_: HttpRequest) -> Result<NamedFile> {
Ok(NamedFile::open("./cache/fonts/bootstrap-icons.woff")?)
}
// Assets
#[get("/assets/wall")]
pub(crate) async fn wallpaper() -> Result<NamedFile> {
Ok(NamedFile::open("/config/wall.avif")?)
}
#[get("/assets/me")]
pub(crate) async fn me_img() -> Result<NamedFile> {
Ok(NamedFile::open("/config/me.avif")?)
}