Skip to content

Commit

Permalink
Add support for json and svg assets (#1413)
Browse files Browse the repository at this point in the history
This PR adds support for `.json` and `.svg` files in the dist folder.
  • Loading branch information
Frederik Rothenberger authored Apr 12, 2023
1 parent 36e5d8e commit 135e6f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/internet_identity/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ pub enum ContentEncoding {
pub enum ContentType {
HTML,
JS,
JSON,
ICO,
WEBP,
CSS,
OCTETSTREAM,
PNG,
SVG,
}

// The <script> tag that loads the 'index.js'
Expand Down Expand Up @@ -118,8 +120,10 @@ fn collect_assets_from_dir(dir: &Dir) -> Vec<(String, Vec<u8>, ContentEncoding,
ContentType::HTML,
),
"ico" => (file_bytes, ContentEncoding::Identity, ContentType::ICO),
"json" => (file_bytes, ContentEncoding::Identity, ContentType::JSON),
"js.gz" => (file_bytes, ContentEncoding::GZip, ContentType::JS),
"png" => (file_bytes, ContentEncoding::Identity, ContentType::PNG),
"svg" => (file_bytes, ContentEncoding::Identity, ContentType::SVG),
"webp" => (file_bytes, ContentEncoding::Identity, ContentType::WEBP),
_ => panic!("Unknown asset type: {}", asset.path().display()),
};
Expand Down
2 changes: 2 additions & 0 deletions src/internet_identity/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ impl ContentType {
match self {
ContentType::HTML => "text/html".to_string(),
ContentType::JS => "text/javascript".to_string(),
ContentType::JSON => "application/json".to_string(),
ContentType::CSS => "text/css".to_string(),
ContentType::ICO => "image/vnd.microsoft.icon".to_string(),
ContentType::WEBP => "image/webp".to_string(),
ContentType::OCTETSTREAM => "application/octet-stream".to_string(),
ContentType::PNG => "image/png".to_string(),
ContentType::SVG => "image/svg+xml".to_string(),
}
}
}
Expand Down

0 comments on commit 135e6f2

Please sign in to comment.