Skip to content
Snippets Groups Projects
Commit 7f78d269 authored by codecraft's avatar codecraft :crocodile:
Browse files

Finished

parent b23f13fc
No related branches found
No related tags found
1 merge request!2Project Completed
/target
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "codegen"
version = "0.1.0"
[package]
name = "codegen"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
pub fn add(left: usize, right: usize) -> usize {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
/target
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "html"
version = "0.1.0"
[package]
name = "html"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
pub fn add(left: usize, right: usize) -> usize {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
[package] [package]
name = "http" name = "http"
version = "0.1.0" version = "1.0.0"
edition = "2021" edition = "2021"
[features] [features]
defautl = [] default = []
secure = [] secure = []
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
......
...@@ -191,7 +191,6 @@ impl FromStr for RawUri { ...@@ -191,7 +191,6 @@ impl FromStr for RawUri {
.parts .parts
.push(RawUriElement::Name(UrlEncodeData::from_raw(part))) .push(RawUriElement::Name(UrlEncodeData::from_raw(part)))
} }
println!("{:?}", result);
Ok(result) Ok(result)
} }
} }
......
import csv
def generate_rust_enum(csv_file):
rust_enum = "use phf::phf_map;\n\nenum Mime {\n"
with open(csv_file, "r") as file:
csv_data = csv.reader(file)
next(csv_data) # Skip the header row
for row in csv_data:
if row[1] == "":
continue
if "DEPRECATED" in row[0]:
continue
name = format_enum_member(row[0:2])
rust_enum += f"\t{name},\n"
rust_enum += "}\n\n"
rust_enum += "impl std::fmt::Display for Mime {\n"
rust_enum += "\tfn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {\n"
rust_enum += "\t\tmatch self {\n"
with open(csv_file, "r") as file:
csv_data = csv.reader(file)
next(csv_data) # Skip the header row
for row in csv_data:
if row[1] == "":
continue
if "DEPRECATED" in row[0]:
continue
name = format_enum_member(row[0:2])
rust_enum += f'\t\t\tMime::{name} => write!(f, "{row[1]}"),\n'
rust_enum += "\t\t}\n\t}\n}\n\n"
rust_enum += "static MimeMap: phf::Map<&'static str, Mime> = phf_map! {\n"
with open(csv_file, "r") as file:
csv_data = csv.reader(file)
next(csv_data)
for row in csv_data:
if row[1] == "":
continue
if "DEPRECATED" in row[0]:
continue
key = row[1]
value = format_enum_member(row[0:2])
rust_enum += f'\t"{key}" => Mime::{value},\n'
rust_enum += "};"
return rust_enum
def format_enum_member(name):
prefix = "".join(name[1].split("/")[0:-1])
name = name[0].split("-")
words = []
parts = []
for part in name:
parts += part.split("+")
for part in parts:
words += part.split(".")
formatted_name = "".join(word.capitalize() for word in words)
if not formatted_name.startswith(prefix.capitalize()):
formatted_name = prefix.capitalize() + formatted_name
return formatted_name
# Usage example
csv_file = "mimes.csv"
rust_enum_code = generate_rust_enum(csv_file)
print(rust_enum_code)
...@@ -110,7 +110,7 @@ checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" ...@@ -110,7 +110,7 @@ checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b"
[[package]] [[package]]
name = "http" name = "http"
version = "0.1.0" version = "1.0.0"
dependencies = [ dependencies = [
"phf", "phf",
"tokio", "tokio",
...@@ -457,7 +457,7 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" ...@@ -457,7 +457,7 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
[[package]] [[package]]
name = "site" name = "site"
version = "0.1.0" version = "1.0.0"
dependencies = [ dependencies = [
"http", "http",
"tokio", "tokio",
......
[package] [package]
name = "site" name = "site"
version = "0.1.0" version = "1.0.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
......
use http::handling::{ use http::handling::{
methods::Method, file_handlers::NamedFile,
routes::{Route, Data}, methods::Method,
request::Request, request::Request,
response::{Response, Outcome, Status}, response::{Outcome, Response, Status},
file_handlers::NamedFile}; routes::{Data, Route},
};
fn static_files_handler(request: Request, _data: Data) -> Outcome<Response, Status, Data> { fn static_files_handler(request: Request, _data: Data) -> Outcome<Response, Status, Data> {
println!("{:?} {}", request.uri, request.uri);
let response = static_files(&request.uri.to_string()); let response = static_files(&request.uri.to_string());
let response = match response { let response = match response {
Ok(dat) => Response { Ok(dat) => Response {
...@@ -25,19 +25,24 @@ fn static_files(path: &str) -> Result<NamedFile, Status> { ...@@ -25,19 +25,24 @@ fn static_files(path: &str) -> Result<NamedFile, Status> {
} }
fn index_handler(_request: Request, _data: Data) -> Outcome<Response, Status, Data> { fn index_handler(_request: Request, _data: Data) -> Outcome<Response, Status, Data> {
Outcome::Success(Response { headers: vec![], cookies: None, status: None, body: Box::new(index()) }) Outcome::Success(Response {
headers: vec![],
cookies: None,
status: None,
body: Box::new(index()),
})
} }
fn index() -> NamedFile { fn index() -> NamedFile {
NamedFile::open("templates/index.html".into()).unwrap() NamedFile::open("../templates/index.html".into()).unwrap()
} }
fn favicon_handler(_request: Request, _data: Data) -> Outcome<Response, Status, Data> { fn favicon_handler(_request: Request, _data: Data) -> Outcome<Response, Status, Data> {
let response = Response { let response = Response {
headers: vec![], headers: vec![],
cookies: None, cookies: None,
status: None, status: None,
body: Box::new(NamedFile::open("/assets/favicon.svg".into()).unwrap()) body: Box::new(NamedFile::open("/assets/favicon.svg".into()).unwrap()),
}; };
Outcome::Success(response) Outcome::Success(response)
} }
...@@ -53,29 +58,29 @@ async fn main() { ...@@ -53,29 +58,29 @@ async fn main() {
rank: 0, rank: 0,
}; };
let static_route = Route { let static_route = Route {
format: None, format: None,
handler: static_files_handler, handler: static_files_handler,
name: Some("static files"), name: Some("static files"),
uri: "<file..>".try_into().unwrap(), uri: "<file..>".try_into().unwrap(),
method: Method::Get, method: Method::Get,
rank: 0 rank: 0,
}; };
let favicon = Route { let favicon = Route {
format: None, format: None,
handler: favicon_handler, handler: favicon_handler,
name: Some("favicon"), name: Some("favicon"),
uri: "favicon.ico".try_into().unwrap(), uri: "favicon.ico".try_into().unwrap(),
method: Method::Get, method: Method::Get,
rank: 0 rank: 0,
}; };
// http::build("127.0.0.1:8000") // http::build("127.0.0.1:8000")
http::build("127.0.0.1:8443", "127.0.0.1:8080") http::build("127.0.0.1:8443", "127.0.0.1:8080")
.await .await
.mount("/".try_into().unwrap(), vec![index_route, favicon])
.mount("/static".try_into().unwrap(), vec![static_route]) .mount("/static".try_into().unwrap(), vec![static_route])
.mount("/".try_into().unwrap(), vec![index_route, favicon])
.launch() .launch()
.await; .await;
} }
Name, format, asdf
vnd.motorola.video,video/vnd.motorola.video,[Tom_McGinty]
vnd.motorola.videop,video/vnd.motorola.videop,[Tom_McGinty]
vnd.mpegurl,video/vnd.mpegurl,[Heiko_Recktenwald]
vnd.ms-playready.media.pyv,video/vnd.ms-playready.media.pyv,[Steve_DiAcetis]
vnd.nokia.interleaved-multimedia,video/vnd.nokia.interleaved-multimedia,[Petteri_Kangaslampi]
vnd.nokia.mp4vr,video/vnd.nokia.mp4vr,[Miska_M._Hannuksela]
vnd.nokia.videovoip,video/vnd.nokia.videovoip,[Nokia]
vnd.objectvideo,video/vnd.objectvideo,[John_Clark]
vnd.radgamettools.bink,video/vnd.radgamettools.bink,[Henrik_Andersson]
vnd.radgamettools.smacker,video/vnd.radgamettools.smacker,[Henrik_Andersson]
vnd.sealed.mpeg1,video/vnd.sealed.mpeg1,[David_Petersen]
vnd.sealed.mpeg4,video/vnd.sealed.mpeg4,[David_Petersen]
vnd.sealed.swf,video/vnd.sealed.swf,[David_Petersen]
vnd.sealedmedia.softseal.mov,video/vnd.sealedmedia.softseal.mov,[David_Petersen]
vnd.uvvu.mp4,video/vnd.uvvu.mp4,[Michael_A_Dolan]
vnd.youtube.yt,video/vnd.youtube.yt,[Google]
vnd.vivo,video/vnd.vivo,[John_Wolfe]
VP8,video/VP8,[RFC7741]
VP9,video/VP9,[RFC-ietf-payload-vp9-16]
.
├── core
│ ├── codegen
│ │ ├── Cargo.lock
│ │ ├── Cargo.toml
│ │ ├── src
│ │ │ └── lib.rs
│ ├── html
│ │ ├── Cargo.lock
│ │ ├── Cargo.toml
│ │ └── src
│ │ └── lib.rs
│ └── http
│ ├── Cargo.lock
│ ├── Cargo.toml
│ └── src
│ ├── handlers
│ │ ├── file_handlers.rs
│ │ ├── handlers.rs
│ │ └── mod.rs
│ ├── lib.rs
│ ├── routing
│ │ ├── methods.rs
│ │ ├── mod.rs
│ │ └── routes.rs
│ ├── setup.rs
│ ├── threading.rs
│ └── utils
│ └── mod.rs
├── README.md
├── site
│ ├── 404.html
│ ├── Cargo.lock
│ ├── Cargo.toml
│ ├── hello.css
│ ├── img.jpg
│ ├── src
│ │ └── main.rs
│ ├── static
│ │ └── hello.html
│ └── target
│ └── CACHEDIR.TAG
└── tree.txt
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment