mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-07-12 00:32:20 +08:00
Add ability to host webui card image files
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
version: '3'
|
|
||||||
services:
|
services:
|
||||||
sif2-ew:
|
sif2-ew:
|
||||||
image: sif2-ew:latest
|
image: sif2-ew:latest
|
||||||
@@ -14,6 +13,7 @@ services:
|
|||||||
HIDDEN: false # Will disable the webui
|
HIDDEN: false # Will disable the webui
|
||||||
DISABLE_IMPORTS: false # Will disable account imports
|
DISABLE_IMPORTS: false # Will disable account imports
|
||||||
DISABLE_EXPORTS: false # Will disable account exports
|
DISABLE_EXPORTS: false # Will disable account exports
|
||||||
|
#IMAGE_ASSET_PATH: /images/ # Images for cards in webui (will default to the public server)
|
||||||
|
|
||||||
# Everything below is for the "Help" page
|
# Everything below is for the "Help" page
|
||||||
#ANDROID_GLOBAL: "link.to/patched/android/global.apk"
|
#ANDROID_GLOBAL: "link.to/patched/android/global.apk"
|
||||||
@@ -25,4 +25,7 @@ services:
|
|||||||
- 8080:8080
|
- 8080:8080
|
||||||
volumes:
|
volumes:
|
||||||
- ./data:/data
|
- ./data:/data
|
||||||
|
# You can download from https://git.ethanthesleepy.one/ethanaobrien/ew-webui/releases/download/images/card-thumbnails.zip
|
||||||
|
# No, you should not have a nested folder EXAMPLE: `images/FILENAME.webp`
|
||||||
|
#- ./images:/images
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
@@ -25,4 +25,6 @@ asset_android_en=$([ "$EN_ANDROID_ASSET_HASH" != "" ] && echo "--en-android-asse
|
|||||||
|
|
||||||
asset_ios_en=$([ "$EN_IOS_ASSET_HASH" != "" ] && echo "--en-ios-asset-hash $EN_IOS_ASSET_HASH" || echo "")
|
asset_ios_en=$([ "$EN_IOS_ASSET_HASH" != "" ] && echo "--en-ios-asset-hash $EN_IOS_ASSET_HASH" || echo "")
|
||||||
|
|
||||||
/root/ew/ew --path $directory --port $port --npps4 $npps4 $asset_android_jp $asset_ios_jp $asset_android_en $asset_ios_en $exports $imports $purge $hidden $https --global-android "$ANDROID_GLOBAL" --japan-android "$ANDROID_JAPAN" --global-ios "$IOS_GLOBAL" --japan-ios "$IOS_JAPAN" --assets-url "$ASSET_URL" --max-time $maxTime
|
image_asset_path=$([ "$IMAGE_ASSET_PATH" != "" ] && echo "--image-asset-path $IMAGE_ASSET_PATH" || echo "")
|
||||||
|
|
||||||
|
/root/ew/ew --path $directory --port $port --npps4 $npps4 $asset_android_jp $asset_ios_jp $asset_android_en $asset_ios_en $exports $imports $purge $hidden $https $image_asset_path --global-android "$ANDROID_GLOBAL" --japan-android "$ANDROID_JAPAN" --global-ios "$IOS_GLOBAL" --japan-ios "$IOS_JAPAN" --assets-url "$ASSET_URL" --max-time $maxTime
|
||||||
|
|||||||
@@ -57,7 +57,10 @@ pub struct Args {
|
|||||||
pub en_android_asset_hash: String,
|
pub en_android_asset_hash: String,
|
||||||
|
|
||||||
#[arg(long, default_value = "", help = "Asset hash for JP Android client.")]
|
#[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 {
|
pub fn get_args() -> Args {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use actix_web::{
|
|||||||
use json::{JsonValue, object};
|
use json::{JsonValue, object};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use include_dir::{include_dir, Dir};
|
use include_dir::{include_dir, Dir};
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
use crate::include_file;
|
use crate::include_file;
|
||||||
use crate::router::{userdata, items};
|
use crate::router::{userdata, items};
|
||||||
@@ -168,6 +169,25 @@ pub fn main(req: HttpRequest) -> HttpResponse {
|
|||||||
.insert_header(ContentType(mime))
|
.insert_header(ContentType(mime))
|
||||||
.insert_header(("content-length", body.len()))
|
.insert_header(("content-length", body.len()))
|
||||||
.body(body);
|
.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()
|
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 total_pages = (total_len as f64 / max as f64).ceil() as usize;
|
||||||
|
let args = crate::get_args();
|
||||||
|
|
||||||
let resp = object!{
|
let resp = object!{
|
||||||
total_pages: total_pages,
|
total_pages: total_pages,
|
||||||
current: page_items
|
current: page_items,
|
||||||
|
image_path: args.image_asset_path
|
||||||
};
|
};
|
||||||
|
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
|
|||||||
2
webui
2
webui
Submodule webui updated: 91919fac81...7fba8d617e
Reference in New Issue
Block a user