|
1 |
| -include!(concat!(env!("OUT_DIR"), "/assets.rs")); |
| 1 | +// All assets |
| 2 | +// |
| 3 | +// This file describes which assets are used and how (content, content type and content encoding). |
| 4 | + |
| 5 | +use sha2::Digest; |
| 6 | + |
| 7 | +#[derive(Debug, PartialEq, Eq)] |
| 8 | +pub enum ContentEncoding { |
| 9 | + Identity, |
| 10 | + GZip, |
| 11 | +} |
| 12 | + |
| 13 | +#[derive(Debug, PartialEq, Eq)] |
| 14 | +pub enum ContentType { |
| 15 | + HTML, |
| 16 | + JS, |
| 17 | + ICO, |
| 18 | + WEBP, |
| 19 | + SVG |
| 20 | +} |
| 21 | + |
| 22 | +pub fn for_each_asset(mut f: impl FnMut(&'static str, ContentEncoding, ContentType, &'static [u8], &[u8; 32])) { |
| 23 | + |
| 24 | + let index_html = include_bytes!("../../../dist/index.html"); |
| 25 | + |
| 26 | + let assets: [ (&str, &[u8], ContentEncoding, ContentType); 8] = [ |
| 27 | + ("/", |
| 28 | + index_html, |
| 29 | + ContentEncoding::Identity, |
| 30 | + ContentType::HTML, |
| 31 | + ), |
| 32 | + // The FAQ and about pages are the same webapp, but the webapp routes to the correct page |
| 33 | + ( |
| 34 | + "/faq", |
| 35 | + index_html, |
| 36 | + ContentEncoding::Identity, |
| 37 | + ContentType::HTML, |
| 38 | + ), |
| 39 | + ( |
| 40 | + "/about", |
| 41 | + index_html, |
| 42 | + ContentEncoding::Identity, |
| 43 | + ContentType::HTML, |
| 44 | + ), |
| 45 | + ( |
| 46 | + "/index.html", |
| 47 | + index_html, |
| 48 | + ContentEncoding::Identity, |
| 49 | + ContentType::HTML, |
| 50 | + ), |
| 51 | + ( |
| 52 | + "/index.js", |
| 53 | + include_bytes!("../../../dist/index.js.gz"), |
| 54 | + ContentEncoding::GZip, |
| 55 | + ContentType::JS, |
| 56 | + ), |
| 57 | + ( |
| 58 | + "/loader.webp", |
| 59 | + include_bytes!("../../../dist/loader.webp"), |
| 60 | + ContentEncoding::Identity, |
| 61 | + ContentType::WEBP, |
| 62 | + ), |
| 63 | + ( |
| 64 | + "/favicon.ico", |
| 65 | + include_bytes!("../../../dist/favicon.ico"), |
| 66 | + ContentEncoding::Identity, |
| 67 | + ContentType::ICO, |
| 68 | + ), |
| 69 | + ( |
| 70 | + "/ic-badge.svg", |
| 71 | + include_bytes!("../../../dist/ic-badge.svg"), |
| 72 | + ContentEncoding::Identity, |
| 73 | + ContentType::SVG, |
| 74 | + ), |
| 75 | + ]; |
| 76 | + |
| 77 | + for (name, content, encoding, content_type) in assets { |
| 78 | + let hash = hash_content(content); |
| 79 | + f(name, encoding, content_type, content, &hash); |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | + |
| 84 | +// Hash the content of an asset in an `ic_certified_map` friendly way |
| 85 | +fn hash_content(bytes: &[u8]) -> [u8; 32] { |
| 86 | + sha2::Sha256::digest(bytes).into() |
| 87 | +} |
0 commit comments