use std::fmt::{Display, Formatter};
#[derive(Clone, Debug)]
#[non_exhaustive]
pub enum UploadWarning {
Exists,
WasDeleted,
Duplicate,
DuplicateArchive,
BadFilename,
Unknown(String),
}
impl UploadWarning {
pub fn from_key(key: String) -> Self {
match key.as_str() {
"exists" => Self::Exists,
"was-deleted" => Self::WasDeleted,
"duplicate" => Self::Duplicate,
"duplicate-archive" => Self::DuplicateArchive,
"badfilename" => Self::BadFilename,
_ => Self::Unknown(key),
}
}
}
impl Display for UploadWarning {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
UploadWarning::Exists => {
"A file with the given name already exists"
}
UploadWarning::WasDeleted => {
"A file with the given name used to exist but has been deleted"
}
UploadWarning::Duplicate => {
"The uploaded file exists under a different (or the same) name"
}
UploadWarning::DuplicateArchive => {
"The uploaded used to exist under a different (or the same) name but has been deleted"
}
UploadWarning::BadFilename => {
"The file name supplied is not acceptable on this wiki"
}
UploadWarning::Unknown(msg) => {
msg
}
}
)
}
}