Skip to content

Commit 32ff012

Browse files
committed
asset logger
1 parent 518e124 commit 32ff012

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

terraps/src/core/asset.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use axum::{
88
};
99
use reqwest::{get, StatusCode};
1010
use serde::Deserialize;
11-
use serde_json::Value;
11+
use serde_json::{json, Value};
1212
use std::{fmt::Display, fs::create_dir_all, io::Cursor, path::Path as StdPath};
1313
use tokio::{fs::File, io::copy};
1414
use tokio_util::io::ReaderStream;
@@ -18,6 +18,7 @@ use common_utils::{read_json, write_json};
1818

1919
const BASE_PATH_CN: &str = "https://ak.hycdn.cn/assetbundle/official/Android/assets/";
2020
const BASE_PATH_GL: &str = "https://ark-us-static-online.yo-star.com/assetbundle/official/Android/assets/";
21+
const ASSETS_JSON: &str = "./assets/assets.json";
2122

2223
#[derive(Deserialize)]
2324
pub struct Asset {
@@ -61,6 +62,13 @@ pub async fn get_file(Path(asset): Path<Asset>) -> Response {
6162
let path = format!("./assets/{hash}/redirect/");
6263
let config = read_json(CONFIG_JSON_PATH);
6364
let mode = config["server"]["mode"].as_str().unwrap();
65+
let mut assets_list = if !StdPath::new(ASSETS_JSON).exists() {
66+
json!({hash: []})
67+
} else {
68+
read_json(ASSETS_JSON)
69+
};
70+
assets_list[hash].as_array_mut().unwrap().push(json!(name));
71+
write_json(ASSETS_JSON, &assets_list);
6472
if config["assets"]["downloadLocally"].as_bool().unwrap() {
6573
if !StdPath::new(&path).exists() {
6674
create_dir_all(&path).unwrap();

0 commit comments

Comments
 (0)