Return None for unknown MIME types and ignore paste with warning
This commit is contained in:
parent
08d442aee2
commit
b8ac39ade5
2 changed files with 47 additions and 29 deletions
20
src/app.rs
20
src/app.rs
|
|
@ -3531,8 +3531,16 @@ impl Application for App {
|
|||
});
|
||||
}
|
||||
Message::PasteImageContents(to, contents) => {
|
||||
let Some(extension) = contents.extension() else {
|
||||
log::warn!(
|
||||
"Ignoring paste: unknown image MIME type {:?}",
|
||||
contents.mime_type
|
||||
);
|
||||
return Task::none();
|
||||
};
|
||||
|
||||
// Generate unique filename for the pasted image
|
||||
let base_name = format!("{}.{}", fl!("pasted-image"), contents.extension());
|
||||
let base_name = format!("{}.{}", fl!("pasted-image"), extension);
|
||||
let base_path = to.join(&base_name);
|
||||
let final_path = copy_unique_path(&base_path, &to);
|
||||
|
||||
|
|
@ -3558,8 +3566,16 @@ impl Application for App {
|
|||
});
|
||||
}
|
||||
Message::PasteVideoContents(to, contents) => {
|
||||
let Some(extension) = contents.extension() else {
|
||||
log::warn!(
|
||||
"Ignoring paste: unknown video MIME type {:?}",
|
||||
contents.mime_type
|
||||
);
|
||||
return Task::none();
|
||||
};
|
||||
|
||||
// Generate unique filename for the pasted video
|
||||
let base_name = format!("{}.{}", fl!("pasted-video"), contents.extension());
|
||||
let base_name = format!("{}.{}", fl!("pasted-video"), extension);
|
||||
let base_path = to.join(&base_name);
|
||||
let final_path = copy_unique_path(&base_path, &to);
|
||||
|
||||
|
|
|
|||
|
|
@ -211,21 +211,22 @@ impl TryFrom<(Vec<u8>, String)> for ClipboardPasteImage {
|
|||
|
||||
impl ClipboardPasteImage {
|
||||
/// Get the file extension for the image based on MIME type.
|
||||
pub fn extension(&self) -> &'static str {
|
||||
/// Returns None if the MIME type is not recognized.
|
||||
pub fn extension(&self) -> Option<&'static str> {
|
||||
match self.mime_type.as_str() {
|
||||
"image/png" | "image/x-png" => "png",
|
||||
"image/jpeg" | "image/pjpeg" => "jpg",
|
||||
"image/gif" => "gif",
|
||||
"image/bmp" | "image/x-bmp" | "image/x-ms-bmp" => "bmp",
|
||||
"image/webp" => "webp",
|
||||
"image/tiff" | "image/x-tiff" => "tiff",
|
||||
"image/svg+xml" => "svg",
|
||||
"image/x-icon" | "image/vnd.microsoft.icon" => "ico",
|
||||
"image/avif" => "avif",
|
||||
"image/heic" => "heic",
|
||||
"image/heif" => "heif",
|
||||
"image/jxl" => "jxl",
|
||||
_ => "png", // Default to png
|
||||
"image/png" | "image/x-png" => Some("png"),
|
||||
"image/jpeg" | "image/pjpeg" => Some("jpg"),
|
||||
"image/gif" => Some("gif"),
|
||||
"image/bmp" | "image/x-bmp" | "image/x-ms-bmp" => Some("bmp"),
|
||||
"image/webp" => Some("webp"),
|
||||
"image/tiff" | "image/x-tiff" => Some("tiff"),
|
||||
"image/svg+xml" => Some("svg"),
|
||||
"image/x-icon" | "image/vnd.microsoft.icon" => Some("ico"),
|
||||
"image/avif" => Some("avif"),
|
||||
"image/heic" => Some("heic"),
|
||||
"image/heif" => Some("heif"),
|
||||
"image/jxl" => Some("jxl"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -272,20 +273,21 @@ impl TryFrom<(Vec<u8>, String)> for ClipboardPasteVideo {
|
|||
|
||||
impl ClipboardPasteVideo {
|
||||
/// Get the file extension for the video based on MIME type.
|
||||
pub fn extension(&self) -> &'static str {
|
||||
/// Returns None if the MIME type is not recognized.
|
||||
pub fn extension(&self) -> Option<&'static str> {
|
||||
match self.mime_type.as_str() {
|
||||
"video/mp4" => "mp4",
|
||||
"video/webm" => "webm",
|
||||
"video/ogg" => "ogv",
|
||||
"video/mpeg" => "mpeg",
|
||||
"video/quicktime" => "mov",
|
||||
"video/x-msvideo" | "video/avi" => "avi",
|
||||
"video/x-matroska" => "mkv",
|
||||
"video/x-flv" => "flv",
|
||||
"video/3gpp" => "3gp",
|
||||
"video/3gpp2" => "3g2",
|
||||
"video/x-ms-wmv" => "wmv",
|
||||
_ => "mp4", // Default to mp4
|
||||
"video/mp4" => Some("mp4"),
|
||||
"video/webm" => Some("webm"),
|
||||
"video/ogg" => Some("ogv"),
|
||||
"video/mpeg" => Some("mpeg"),
|
||||
"video/quicktime" => Some("mov"),
|
||||
"video/x-msvideo" | "video/avi" => Some("avi"),
|
||||
"video/x-matroska" => Some("mkv"),
|
||||
"video/x-flv" => Some("flv"),
|
||||
"video/3gpp" => Some("3gp"),
|
||||
"video/3gpp2" => Some("3g2"),
|
||||
"video/x-ms-wmv" => Some("wmv"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue