diff options
Diffstat (limited to 'src/assets.rs')
-rw-r--r-- | src/assets.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/assets.rs b/src/assets.rs new file mode 100644 index 0000000..dc46c78 --- /dev/null +++ b/src/assets.rs @@ -0,0 +1,27 @@ +use sha2::{Digest, Sha256}; +use std::collections::HashMap; +use std::fs; +use std::iter::FromIterator; + +pub fn get() -> HashMap<String, String> { + let paths = fs::read_dir("assets").unwrap().map(|e| { + let path = format!("{}", e.unwrap().path().display()); + let file = fs::read(&path).unwrap(); + let mut path_iter = path.split("/"); + path_iter.next(); + let name = path_iter.collect::<Vec<&str>>().join("/"); + let hashed = format!("/assets/{}/{}", sha256(file), name); + (name, hashed) + }); + HashMap::from_iter(paths) +} + +fn sha256(input: Vec<u8>) -> String { + let mut hasher = Sha256::new(); + hasher.update(input); + hasher + .finalize() + .iter() + .map(|b| format!("{:x}", b)) + .collect() +} |