repl export-chat-requires destination path

and combind the public accessible functions into one
This commit is contained in:
Simon Laux
2020-06-13 05:27:36 +02:00
parent 897d2f4a08
commit 4bf07ccc71
2 changed files with 22 additions and 26 deletions

View File

@@ -38,20 +38,29 @@ use futures::future::join_all;
use serde::Serialize;
#[derive(Debug)]
pub struct ExportChatResult {
struct ExportChatResult {
chat_json: String,
// locations_geo_json: String,
message_info: Vec<(u32, String, Option<String>)>,
referenced_blobs: Vec<String>,
}
pub fn pack_exported_chat(
pub async fn export_chat_to_zip(context: &Context, chat_id: ChatId, filename: &str) -> () {
let res = export_chat_data(&context, chat_id).await;
let destination = std::path::Path::new(filename);
let pack_res = pack_exported_chat(&context, res, destination);
match &pack_res {
Ok(()) => println!("Exported chat successfully to {}", filename),
Err(err) => println!("Error {:?}", err),
};
}
fn pack_exported_chat(
context: &Context,
artifact: ExportChatResult,
filename: &str,
destination: &Path,
) -> zip::result::ZipResult<()> {
let path = std::path::Path::new(filename);
let file = std::fs::File::create(&path).unwrap();
let file = std::fs::File::create(&destination).unwrap();
let mut zip = zip::ZipWriter::new(file);
@@ -88,6 +97,8 @@ pub fn pack_exported_chat(
}
}
// todo maybe memory optimisation -> load message source here and pack it directly into zip
zip.finish()?;
Ok(())
}
@@ -169,7 +180,7 @@ impl MessageJSON {
}
}
pub async fn export_chat(context: &Context, chat_id: ChatId) -> ExportChatResult {
async fn export_chat_data(context: &Context, chat_id: ChatId) -> ExportChatResult {
let mut blobs = Vec::new();
let mut chat_author_ids = Vec::new();
// get all messages