mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-01-12 08:12:36 +08:00
Ship files for offline android/ios servers
This commit is contained in:
@@ -26,7 +26,29 @@ async fn maintenance(_req: HttpRequest) -> HttpResponse {
|
||||
.body(r#"{"opened_at":"2024-02-05 02:00:00","closed_at":"2024-02-05 04:00:00","message":":(","server":1,"gamelib":0}"#)
|
||||
}
|
||||
|
||||
#[cfg(feature = "library")]
|
||||
use include_dir::{include_dir, Dir};
|
||||
|
||||
#[cfg(all(feature = "library", target_os = "ios"))]
|
||||
static SPART_FILES: Dir<'_> = include_dir!("assets/iOS/");
|
||||
|
||||
#[cfg(all(feature = "library", target_os = "android"))]
|
||||
static SPART_FILES: Dir<'_> = include_dir!("assets/Android/");
|
||||
|
||||
fn handle_assets(req: HttpRequest) -> HttpResponse {
|
||||
#[cfg(feature = "library")]
|
||||
{
|
||||
let lang: String = req.match_info().get("lang").unwrap_or("JP").parse().unwrap_or(String::from("JP"));
|
||||
let file_name: String = req.match_info().get("file").unwrap().parse().unwrap();
|
||||
let hash: String = req.match_info().get("file").unwrap().parse().unwrap();
|
||||
if let Some(file) = SPART_FILES.get_file(format!("{lang}/{hash}/{file_name}")) {
|
||||
let body = file.contents();
|
||||
return HttpResponse::Ok()
|
||||
.insert_header(ContentType(mime::APPLICATION_OCTET_STREAM))
|
||||
.insert_header(("content-length", body.len()))
|
||||
.body(body);
|
||||
}
|
||||
}
|
||||
let file_path = format!("assets{}", req.path());
|
||||
let exists = fs::exists(&file_path);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user