mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-07-12 08:42:20 +08:00
Add ability to host webui card image files
This commit is contained in:
@@ -7,6 +7,7 @@ use actix_web::{
|
||||
use json::{JsonValue, object};
|
||||
use lazy_static::lazy_static;
|
||||
use include_dir::{include_dir, Dir};
|
||||
use std::fs;
|
||||
|
||||
use crate::include_file;
|
||||
use crate::router::{userdata, items};
|
||||
@@ -168,6 +169,25 @@ pub fn main(req: HttpRequest) -> HttpResponse {
|
||||
.insert_header(ContentType(mime))
|
||||
.insert_header(("content-length", body.len()))
|
||||
.body(body);
|
||||
} else if path.starts_with("webui/images/card-thumbnails") {
|
||||
let args = crate::get_args();
|
||||
|
||||
let file_name = path.split("/").last().unwrap_or("");
|
||||
let file_path = format!("{}/{}", args.image_asset_path, file_name).replace("//", "/");
|
||||
if args.image_asset_path != "" && let Ok(body) = fs::read(file_path) {
|
||||
let mime = mime_guess::from_path(path).first_or_octet_stream();
|
||||
return HttpResponse::Ok()
|
||||
.insert_header(ContentType(mime))
|
||||
.insert_header(("content-length", body.len()))
|
||||
.body(body);
|
||||
} else {
|
||||
if args.image_asset_path != "" {
|
||||
println!("File '{file_name}' was requested, but no file was found on the disk!");
|
||||
}
|
||||
return HttpResponse::SeeOther()
|
||||
.insert_header(("location", format!("https://sif2-api.ethanthesleepy.one{}", req.path())))
|
||||
.body("");
|
||||
}
|
||||
}
|
||||
|
||||
HttpResponse::Found()
|
||||
@@ -269,10 +289,12 @@ pub fn get_card_info(req: HttpRequest) -> HttpResponse {
|
||||
}
|
||||
|
||||
let total_pages = (total_len as f64 / max as f64).ceil() as usize;
|
||||
let args = crate::get_args();
|
||||
|
||||
let resp = object!{
|
||||
total_pages: total_pages,
|
||||
current: page_items
|
||||
current: page_items,
|
||||
image_path: args.image_asset_path
|
||||
};
|
||||
|
||||
HttpResponse::Ok()
|
||||
|
||||
Reference in New Issue
Block a user