Add ability to host webui card image files

This commit is contained in:
Ethan O'Brien
2026-02-19 14:04:31 -06:00
parent 8a1d33bd2b
commit 956634d8ab
5 changed files with 35 additions and 5 deletions

View File

@@ -57,7 +57,10 @@ pub struct Args {
pub en_android_asset_hash: String,
#[arg(long, default_value = "", help = "Asset hash for JP Android client.")]
pub jp_android_asset_hash: String
pub jp_android_asset_hash: String,
#[arg(long, default_value = "", help = "Path to image assets.")]
pub image_asset_path: String
}
pub fn get_args() -> Args {

View File

@@ -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()