blob: dc46c78a90933d6634213194039b3237b021970e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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()
}
|