Skip to content

Commit

Permalink
Support attaching multiple files in Telegram
Browse files Browse the repository at this point in the history
  • Loading branch information
GamePad64 committed Dec 21, 2024
1 parent 47f1c0d commit 999605c
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 69 deletions.
91 changes: 46 additions & 45 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions notifico-attachment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub struct AttachedFile {
pub file_name: String,
pub mime_type: Mime,
pub size: u64,
pub plugin_values: HashMap<String, String>,
pub extras: HashMap<String, String>,
}

impl AttachedFile {
Expand Down Expand Up @@ -111,7 +111,7 @@ impl AttachmentPlugin {
file_name,
mime_type,
size,
plugin_values: HashMap::new(),
extras: info.extras.clone(),
});
}
unimplemented!()
Expand Down
1 change: 1 addition & 0 deletions notifico-core/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct EventContext(pub Map<String, Value>);
pub struct AttachmentMetadata {
pub url: Url,
pub file_name: Option<String>,
pub extras: HashMap<String, String>,
}

#[derive(Default, Clone, Debug, Serialize, Deserialize)]
Expand Down
2 changes: 2 additions & 0 deletions notificox/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use notifico_template::source::fs::FilesystemSource;
use notifico_template::{PreRenderedTemplate, TemplateSelector, Templater};
use notifico_transports::all_transports;
use serde_json::json;
use std::collections::HashMap;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::Arc;
Expand Down Expand Up @@ -177,6 +178,7 @@ async fn main() {
attachments.push(AttachmentMetadata {
url: Url::from_file_path(abspath).unwrap(),
file_name: None,
extras: HashMap::new(),
})
}

Expand Down
4 changes: 2 additions & 2 deletions transports/notifico-smtp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl EmailTransport {
let mut attachments_inline = vec![];

for attachment in attachments {
if attachment.plugin_values.contains_key("email.cid") {
if attachment.extras.contains_key("email.cid") {
attachments_inline.push(attachment);
} else {
attachments_mixed.push(attachment);
Expand All @@ -165,7 +165,7 @@ impl EmailTransport {
let mut mp_related = MultiPart::related().build();
mp_related = mp_related.singlepart(SinglePart::html(rendered.body_html));
for mut attachment in attachments_inline {
let cid = attachment.plugin_values.get("email.cid").unwrap().clone();
let cid = attachment.extras.get("email.cid").unwrap().clone();

let content_type = ContentType::parse(attachment.mime_type.as_ref()).unwrap();
let attach =
Expand Down
Loading

0 comments on commit 999605c

Please sign in to comment.