-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ef54af
commit cc1551b
Showing
7 changed files
with
843 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "generate-database" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
async-std = { version = "1.11", features = ["attributes"] } | ||
cfg-if = "1" | ||
phf_codegen = "0.10" | ||
serde = { version = "1", features = ["derive"] } | ||
serde_json = "1" | ||
surf = { version = "2.3.2", default-features = false, features = ["h1-client-rustls"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::collections::HashMap; | ||
use std::env; | ||
use std::path::Path; | ||
|
||
use async_std::fs::File; | ||
use async_std::io::BufWriter; | ||
use async_std::io::WriteExt; | ||
use serde::Deserialize; | ||
|
||
#[derive(Debug, Deserialize, Clone)] | ||
struct MimeInfo { | ||
compressible: Option<bool>, | ||
} | ||
|
||
#[async_std::main] | ||
async fn main() -> surf::Result<()> { | ||
let path = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()) | ||
.join("..") | ||
.join("src") | ||
.join("codegen_database.rs"); | ||
let mut file = BufWriter::new(File::create(&path).await?); | ||
|
||
let mime_db: HashMap<String, MimeInfo> = | ||
surf::get("https://raw.githubusercontent.com/jshttp/mime-db/master/db.json") | ||
.recv_json() | ||
.await?; | ||
|
||
let mut builder = phf_codegen::Set::new(); | ||
|
||
for (key, info) in mime_db { | ||
if matches!(info.compressible, Some(yes) if yes) { | ||
builder.entry(key); | ||
} | ||
} | ||
|
||
writeln!( | ||
&mut file, | ||
"pub(crate) const MIME_DB: phf::Set<&'static str> =\n{};\n", | ||
builder.build() | ||
) | ||
.await?; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.