mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-04-01 17:45:35 +00:00
initial commit
This commit is contained in:
parent
381a398de1
commit
a7083852c3
22 changed files with 446 additions and 15 deletions
62
src/client/response/header/mime.rs
Normal file
62
src/client/response/header/mime.rs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
use glib::{GString, Uri};
|
||||
use std::path::Path;
|
||||
|
||||
pub enum Mime {
|
||||
TextGemini,
|
||||
TextPlain,
|
||||
ImagePng,
|
||||
ImageGif,
|
||||
ImageJpeg,
|
||||
ImageWebp,
|
||||
} // @TODO
|
||||
|
||||
pub fn from_header(buffer: &[u8] /* @TODO */) -> Option<Mime> {
|
||||
from_string(&match GString::from_utf8(buffer.to_vec()) {
|
||||
Ok(result) => result,
|
||||
Err(_) => return None, // @TODO error handler?
|
||||
})
|
||||
}
|
||||
|
||||
pub fn from_path(path: &Path) -> Option<Mime> {
|
||||
match path.extension().and_then(|extension| extension.to_str()) {
|
||||
Some("gmi") | Some("gemini") => Some(Mime::TextGemini),
|
||||
Some("txt") => Some(Mime::TextPlain),
|
||||
Some("png") => Some(Mime::ImagePng),
|
||||
Some("gif") => Some(Mime::ImageGif),
|
||||
Some("jpeg") | Some("jpg") => Some(Mime::ImageJpeg),
|
||||
Some("webp") => Some(Mime::ImageWebp),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_string(value: &str) -> Option<Mime> {
|
||||
if value.contains("text/gemini") {
|
||||
return Some(Mime::TextGemini);
|
||||
}
|
||||
|
||||
if value.contains("text/plain") {
|
||||
return Some(Mime::TextPlain);
|
||||
}
|
||||
|
||||
if value.contains("image/gif") {
|
||||
return Some(Mime::ImageGif);
|
||||
}
|
||||
|
||||
if value.contains("image/jpeg") {
|
||||
return Some(Mime::ImageJpeg);
|
||||
}
|
||||
|
||||
if value.contains("image/webp") {
|
||||
return Some(Mime::ImageWebp);
|
||||
}
|
||||
|
||||
if value.contains("image/png") {
|
||||
return Some(Mime::ImagePng);
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn from_uri(uri: &Uri) -> Option<Mime> {
|
||||
from_path(Path::new(&uri.to_string()))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue