Skip to content

Commit 547a2b2

Browse files
feat: add save_text_file and save_text_files
1 parent cd6b684 commit 547a2b2

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/file_conversion.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,29 @@ use std::path::Path;
33
use crate::types::{MediaFile, TextFile};
44
use std::io::Write;
55

6+
pub fn save_text_file(notification_from: &u8, file: &TextFile) -> std::io::Result<()> {
7+
let dir_name = format!("cached_files_{}", notification_from);
8+
let dir_path = Path::new(&dir_name);
9+
fs::create_dir_all(dir_path)?;
10+
11+
let file_name = format!("{}_{}", file.id, file.title);
12+
let file_path = dir_path.join(file_name);
13+
14+
let mut f = File::create(file_path)?;
15+
writeln!(f, "{}", file.content)?;
16+
for media_ref in &file.media_refs {
17+
writeln!(f, "MediaFile attached: {}_{}", media_ref.location, media_ref.id)?;
18+
}
19+
Ok(())
20+
}
21+
22+
pub fn save_text_files(notification_from: &u8, files: &Vec<TextFile>) -> std::io::Result<()> {
23+
for file in files {
24+
save_text_file(notification_from, file)?;
25+
}
26+
Ok(())
27+
}
28+
629
pub fn save_media_file(notification_from: &u8, file: &MediaFile) -> std::io::Result<()> {
730
let dir_name = format!("cached_files_{}", notification_from);
831
let dir_path = Path::new(&dir_name);

0 commit comments

Comments
 (0)