Skip to content

Commit

Permalink
add mime type groups support
Browse files Browse the repository at this point in the history
  • Loading branch information
yggverse committed Dec 11, 2024
1 parent 1911b0a commit e76bc62
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/client/connection/response/meta/mime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,28 @@ use std::path::Path;
/// https://geminiprotocol.net/docs/gemtext-specification.gmi#media-type-parameters
#[derive(Debug)]
pub enum Mime {
// Text
// text
TextGemini,
TextPlain,
// Image
/// Match unlisted `text/*`
Text,
// image
ImageGif,
ImageJpeg,
ImagePng,
ImageSvg,
ImageWebp,
// Audio
/// Match unlisted `image/*`
Image,
// audio
AudioFlac,
AudioMpeg,
AudioOgg,
/// Match unlisted `audio/*`
Audio,
// other
/// Match unlisted `application/*`
Application,
} // @TODO

impl Mime {
Expand Down Expand Up @@ -91,6 +100,10 @@ impl Mime {
return Ok(Some(Self::TextPlain));
}

if value.contains("text/") {
return Ok(Some(Self::Text));
}

// Image
if value.contains("image/gif") {
return Ok(Some(Self::ImageGif));
Expand All @@ -112,6 +125,10 @@ impl Mime {
return Ok(Some(Self::ImageWebp));
}

if value.contains("image/") {
return Ok(Some(Self::Image));
}

// Audio
if value.contains("audio/flac") {
return Ok(Some(Self::AudioFlac));
Expand All @@ -125,6 +142,17 @@ impl Mime {
return Ok(Some(Self::AudioOgg));
}

if value.contains("audio/") {
return Ok(Some(Self::Audio));
}

// Other
if value.contains("application/") {
return Ok(Some(Self::Application));
}

// application/x-tar

// Some type exist, but not defined yet (on status code is 2*)
if value.starts_with("2") && value.contains("/") {
return Err(Error::Undefined);
Expand Down

0 comments on commit e76bc62

Please sign in to comment.