Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file slicing and encryption in thread #550

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions rust/libqaul/src/services/chat/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::{
io::{Read, Write},
path::{Path, PathBuf},
sync::RwLock,
thread,
};

use super::ChatStorage;
Expand Down Expand Up @@ -438,8 +439,8 @@ impl ChatFile {

/// send a file from RPC to users
fn send(
user_account: &UserAccount,
group_id: &Vec<u8>,
user_account: &'static UserAccount,
group_id: &'static Vec<u8>,
path_name: String,
description: String,
) -> Result<bool, String> {
Expand Down Expand Up @@ -518,7 +519,7 @@ impl ChatFile {
let file_path = Self::create_file_path(user_account.id, file_id, extension.as_str());

// TODO: start in new async thread here

thread::spawn(move || {
// copy file
if let Err(e) = fs::copy(path_name.clone(), file_path) {
log::error!("copy file error {}", e.to_string());
Expand Down Expand Up @@ -618,9 +619,9 @@ impl ChatFile {
};
left_size = left_size - read_size;

if let Err(e) = file.read(&mut buffer) {
return Err(e.to_string());
}
// if let Err(e) = file.read(&mut buffer) {
// return Err(e.to_string());
// }

// pack chat file container
let data = proto_net::ChatFileContainer {
Expand All @@ -645,14 +646,13 @@ impl ChatFile {

chunk_index = chunk_index + 1;
}

// set file status to sent
ChatStorage::udate_status(
&user_account.id,
&message_id,
super::rpc_proto::MessageStatus::Sent,
);

}).join().unwrap();
Ok(true)
}

Expand Down Expand Up @@ -987,14 +987,14 @@ impl ChatFile {
Some(proto_rpc::chat_file::Message::SendFileRequest(send_req)) => {
let user_account = UserAccounts::get_by_id(account_id).unwrap();

if let Err(e) = Self::send(
&user_account,
&send_req.group_id,
send_req.path_name,
send_req.description,
) {
log::error!("file rpc send file failed {}", e.to_string());
}
// if let Err(e) = Self::send(
// &user_account,
// &send_req.group_id,
// send_req.path_name,
// send_req.description,
// ) {
// log::error!("file rpc send file failed {}", e.to_string());
// }
}
Some(proto_rpc::chat_file::Message::FileHistory(history_req)) => {
log::trace!("lib->file->history");
Expand Down