Why does async-tungstenite hate me?
This commit is contained in:
parent
78a0ebd18e
commit
04356f991a
8 changed files with 674 additions and 374 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use crate::util::file_util::{get_children, load_file, save_file};
|
||||
use crate::util::file_util::{get_children, get_directory, load_file, save_file};
|
||||
use json::{self, JsonValue, array, object};
|
||||
use std::fs::{self};
|
||||
use std::path::Path;
|
||||
|
|
@ -31,7 +31,12 @@ pub fn add_message(
|
|||
external_user: Uuid,
|
||||
message: &str,
|
||||
) {
|
||||
let user_dir = format!("users/{}/chats/{}", storage_owner, external_user);
|
||||
let user_dir = format!(
|
||||
"{}/users/{}/chats/{}",
|
||||
get_directory(),
|
||||
storage_owner,
|
||||
external_user
|
||||
);
|
||||
|
||||
if let Err(e) = fs::create_dir_all(&user_dir) {
|
||||
log_message(format!("Failed to create chat directory: {}", e));
|
||||
|
|
@ -56,7 +61,6 @@ pub fn add_message(
|
|||
log_message(format!("Failed to parse existing JSON file: {}", file_name));
|
||||
}
|
||||
} else {
|
||||
// New file, use empty array
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::ffi::OsStr;
|
||||
use std::fs::{self, File};
|
||||
use std::io::Read;
|
||||
use std::io::{self, BufReader, Read};
|
||||
use std::path::{Path, PathBuf};
|
||||
use sysinfo::System;
|
||||
use uuid::Uuid;
|
||||
|
|
@ -42,6 +42,36 @@ pub fn delete_user_directory(user_id: Uuid) {
|
|||
let _ = delete_dir_recursive(&user_dir);
|
||||
}
|
||||
|
||||
pub fn load_file_buf(path: &str, name: &str) -> io::Result<BufReader<File>> {
|
||||
let dir = Path::new(&get_directory()).join(path);
|
||||
let file_path = dir.join(name);
|
||||
|
||||
// Ensure the directory exists, create if necessary
|
||||
if !dir.exists() {
|
||||
if let Err(e) = fs::create_dir_all(&dir) {
|
||||
println!("[IMPORTANT] Couldn't create directories: {}", e);
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::NotFound,
|
||||
"Directory creation failed",
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Create the file if it doesn't exist
|
||||
if !file_path.exists() {
|
||||
if let Err(e) = File::create(&file_path) {
|
||||
println!("[IMPORTANT] Couldn't create file: {}", e);
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::NotFound,
|
||||
"File creation failed",
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Open the file and return a BufReader for efficient reading
|
||||
let file = File::open(&file_path)?;
|
||||
Ok(BufReader::new(file))
|
||||
}
|
||||
pub fn load_file(path: &str, name: &str) -> String {
|
||||
let dir = Path::new(&get_directory()).join(path);
|
||||
let file_path = dir.join(name);
|
||||
|
|
|
|||
Loading…
Reference in a new issue