committed by
GitHub
10 changed files with 145 additions and 6 deletions
@ -0,0 +1,27 @@ |
|||||
|
use rocket::http::{ContentType, Status}; |
||||
|
use rust_embed::EmbeddedFile; |
||||
|
use std::borrow::Cow; |
||||
|
use std::ffi::OsStr; |
||||
|
use std::path::PathBuf; |
||||
|
|
||||
|
pub trait EmbeddedFileExt { |
||||
|
fn into_response(self, file: PathBuf) -> Result<(ContentType, Cow<'static, [u8]>), Status>; |
||||
|
} |
||||
|
|
||||
|
impl EmbeddedFileExt for Option<EmbeddedFile> { |
||||
|
fn into_response(self, file: PathBuf) -> Result<(ContentType, Cow<'static, [u8]>), Status> { |
||||
|
match self { |
||||
|
None => Err(Status::NotFound), |
||||
|
Some(embedded_file) => { |
||||
|
let ext = file |
||||
|
.as_path() |
||||
|
.extension() |
||||
|
.and_then(OsStr::to_str) |
||||
|
.ok_or_else(|| Status::new(400))?; |
||||
|
let content_type = |
||||
|
ContentType::from_extension(ext).ok_or_else(|| Status::new(400))?; |
||||
|
Ok::<(ContentType, Cow<[u8]>), Status>((content_type, embedded_file.data)) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
@ -1,5 +1,4 @@ |
|||||
node_modules |
node_modules |
||||
.DS_Store |
.DS_Store |
||||
dist |
|
||||
dist-ssr |
dist-ssr |
||||
*.local |
*.local |
||||
|
@ -0,0 +1,4 @@ |
|||||
|
# Ignore everything in this directory |
||||
|
* |
||||
|
# Except this file |
||||
|
!.gitignore |
@ -0,0 +1,4 @@ |
|||||
|
# Ignore everything in this directory |
||||
|
* |
||||
|
# Except this file |
||||
|
!.gitignore |
Loading…
Reference in new issue