forked from jmug/stoatchat
feat: add asset!() macro to crate
This commit is contained in:
13
src/main.rs
13
src/main.rs
@@ -73,13 +73,13 @@ async fn main() {
|
|||||||
templates: Templates {
|
templates: Templates {
|
||||||
verify: Template {
|
verify: Template {
|
||||||
title: "Verify your Revolt account.".into(),
|
title: "Verify your Revolt account.".into(),
|
||||||
text: include_str!("../assets/templates/verify.txt").into(),
|
text: include_str!(crate::asset!("templates/verify.txt")).into(),
|
||||||
url: format!("{}/login/verify/", *APP_URL),
|
url: format!("{}/login/verify/", *APP_URL),
|
||||||
html: None,
|
html: None,
|
||||||
},
|
},
|
||||||
reset: Template {
|
reset: Template {
|
||||||
title: "Reset your Revolt password.".into(),
|
title: "Reset your Revolt password.".into(),
|
||||||
text: include_str!("../assets/templates/reset.txt").into(),
|
text: include_str!(crate::asset!("templates/reset.txt")).into(),
|
||||||
url: format!("{}/login/reset/", *APP_URL),
|
url: format!("{}/login/reset/", *APP_URL),
|
||||||
html: None,
|
html: None,
|
||||||
},
|
},
|
||||||
@@ -139,3 +139,12 @@ async fn main() {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Resolve asset
|
||||||
|
macro_rules! asset {
|
||||||
|
($path:literal) => {
|
||||||
|
concat!(env!("CARGO_MANIFEST_DIR"), "/assets/", $path)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) use asset;
|
||||||
|
|||||||
@@ -62,15 +62,15 @@ pub async fn req(target: String) -> CachedFile {
|
|||||||
match target.chars().last().unwrap() {
|
match target.chars().last().unwrap() {
|
||||||
// 0123456789ABCDEFGHJKMNPQRSTVWXYZ
|
// 0123456789ABCDEFGHJKMNPQRSTVWXYZ
|
||||||
'0' | '1' | '2' | '3' | 'S' | 'Z' => {
|
'0' | '1' | '2' | '3' | 'S' | 'Z' => {
|
||||||
include_bytes!("../../../assets/user/2.png").to_vec()
|
include_bytes!(crate::asset!("user/2.png")).to_vec()
|
||||||
}
|
}
|
||||||
'4' | '5' | '6' | '7' | 'T' => include_bytes!("../../../assets/user/3.png").to_vec(),
|
'4' | '5' | '6' | '7' | 'T' => include_bytes!(crate::asset!("user/3.png")).to_vec(),
|
||||||
'8' | '9' | 'A' | 'B' => include_bytes!("../../../assets/user/4.png").to_vec(),
|
'8' | '9' | 'A' | 'B' => include_bytes!(crate::asset!("user/4.png")).to_vec(),
|
||||||
'C' | 'D' | 'E' | 'F' | 'V' => include_bytes!("../../../assets/user/5.png").to_vec(),
|
'C' | 'D' | 'E' | 'F' | 'V' => include_bytes!(crate::asset!("user/5.png")).to_vec(),
|
||||||
'G' | 'H' | 'J' | 'K' | 'W' => include_bytes!("../../../assets/user/6.png").to_vec(),
|
'G' | 'H' | 'J' | 'K' | 'W' => include_bytes!(crate::asset!("user/6.png")).to_vec(),
|
||||||
'M' | 'N' | 'P' | 'Q' | 'X' => include_bytes!("../../../assets/user/7.png").to_vec(),
|
'M' | 'N' | 'P' | 'Q' | 'X' => include_bytes!(crate::asset!("user/7.png")).to_vec(),
|
||||||
/*'0' | '1' | '2' | '3' | 'R' | 'Y'*/
|
/*'0' | '1' | '2' | '3' | 'R' | 'Y'*/
|
||||||
_ => include_bytes!("../../../assets/user/1.png").to_vec(),
|
_ => include_bytes!(crate::asset!("user/1.png")).to_vec(),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user