Accept documents in media message ingestion
This commit is contained in:
parent
31f6beb161
commit
16e938e756
1 changed files with 11 additions and 26 deletions
15
src/main.rs
15
src/main.rs
|
|
@ -587,20 +587,6 @@ async fn handle_media_message(
|
|||
|
||||
if let Some(document) = msg.document() {
|
||||
let mime = document.mime_type.as_ref().map(|m| m.essence_str());
|
||||
let is_media = if let Some(mime) = mime {
|
||||
mime.starts_with("image/") || mime.starts_with("video/")
|
||||
} else {
|
||||
document
|
||||
.file_name
|
||||
.as_deref()
|
||||
.and_then(|name| Path::new(name).extension().and_then(|ext| ext.to_str()))
|
||||
.map(|ext| matches!(
|
||||
ext.to_ascii_lowercase().as_str(),
|
||||
"png" | "jpg" | "jpeg" | "gif" | "webp" | "bmp" | "mp4" | "mov" | "mkv"
|
||||
))
|
||||
.unwrap_or(false)
|
||||
};
|
||||
if is_media {
|
||||
fs::create_dir_all(&media_dir)
|
||||
.with_context(|| format!("create media dir {}", media_dir.display()))?;
|
||||
let ext = mime.and_then(extension_from_mime);
|
||||
|
|
@ -615,7 +601,6 @@ async fn handle_media_message(
|
|||
handle_single_item(bot.clone(), chat_id, state.clone(), &entry_text, Some(msg.id)).await?;
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(video) = msg.video() {
|
||||
fs::create_dir_all(&media_dir)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue