refactor to rocket

This commit is contained in:
JMARyA 2024-07-10 14:13:37 +02:00
parent e1c45d6a45
commit 7507f94141
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
14 changed files with 1194 additions and 895 deletions

67
src/pages/bootstrap.rs Normal file
View file

@ -0,0 +1,67 @@
use rocket::{fs::NamedFile, get};
use std::io::Write;
async fn download_file(url: &str, file: &str) {
let content = reqwest::get(url).await.expect("couldn't download file");
std::fs::File::create(file)
.expect("could not create file")
.write_all(&content.bytes().await.expect("could not get bytes"))
.expect("could not write file");
}
#[get("/bootstrap.min.css")]
pub async fn bootstrap_css() -> Option<NamedFile> {
NamedFile::open("./cache/bootstrap.mi.await.ok()n.css")
.await
.ok()
}
#[get("/bootstrap-icons.css")]
pub async fn bootstrap_icons() -> Option<NamedFile> {
NamedFile::open("./cache/bootstrap-icon.await.ok()s.css")
.await
.ok()
}
#[get("/bootstrap.bundle.min.js")]
pub async fn bootstrap_js() -> Option<NamedFile> {
NamedFile::open("./cache/bootstrap.b.await.ok()undle.min.js")
.await
.ok()
}
#[get("/fonts/bootstrap-icons.woff2")]
pub async fn bootstrap_font1() -> Option<NamedFile> {
NamedFile::open("./cache/fonts/bootstrap-icons.woff2")
.await
.ok()
}
#[get("/fonts/bootstrap-icons.woff")]
pub async fn bootstrap_font2() -> Option<NamedFile> {
NamedFile::open("./cache/fonts/bootstrap-icons.woff")
.await
.ok()
}
/// Cache Bootstrap files locally
pub 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;
}