mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 09:05:45 +00:00
dump unsupported mime type string
This commit is contained in:
parent
76235da239
commit
2c88f12f2d
2 changed files with 22 additions and 6 deletions
|
|
@ -8,7 +8,7 @@
|
|||
pub mod error;
|
||||
pub use error::Error;
|
||||
|
||||
use glib::{GString, Uri};
|
||||
use glib::{GString, Regex, RegexCompileFlags, RegexMatchFlags, Uri};
|
||||
use std::path::Path;
|
||||
|
||||
/// https://geminiprotocol.net/docs/gemtext-specification.gmi#media-type-parameters
|
||||
|
|
@ -80,7 +80,7 @@ impl Mime {
|
|||
Some("flac") => Ok(Self::AudioFlac),
|
||||
Some("mp3") => Ok(Self::AudioMpeg),
|
||||
Some("oga" | "ogg" | "opus" | "spx") => Ok(Self::AudioOgg),
|
||||
_ => Err(Error::Undefined),
|
||||
_ => Err(Error::Undefined(None)),
|
||||
} // @TODO extension to lowercase
|
||||
}
|
||||
|
||||
|
|
@ -155,7 +155,16 @@ impl Mime {
|
|||
|
||||
// Some type exist, but not defined yet (on status code is 2*)
|
||||
if value.starts_with("2") && value.contains("/") {
|
||||
return Err(Error::Undefined);
|
||||
return Err(Error::Undefined(
|
||||
Regex::split_simple(
|
||||
r"^2\d{1}\s([^\/]+\/[^\s]+)",
|
||||
value,
|
||||
RegexCompileFlags::DEFAULT,
|
||||
RegexMatchFlags::DEFAULT,
|
||||
)
|
||||
.get(1)
|
||||
.map(|this| this.to_string()),
|
||||
));
|
||||
}
|
||||
|
||||
// Done
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use std::fmt::{Display, Formatter, Result};
|
|||
pub enum Error {
|
||||
Decode(std::string::FromUtf8Error),
|
||||
Protocol,
|
||||
Undefined,
|
||||
Undefined(Option<String>),
|
||||
}
|
||||
|
||||
impl Display for Error {
|
||||
|
|
@ -16,8 +16,15 @@ impl Display for Error {
|
|||
Self::Protocol => {
|
||||
write!(f, "Protocol error")
|
||||
}
|
||||
Self::Undefined => {
|
||||
write!(f, "Undefined")
|
||||
Self::Undefined(e) => {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
match e {
|
||||
Some(value) => format!("`{value}` undefined"),
|
||||
None => "Could not parse value".to_string(),
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue