create config file
This commit is contained in:
parent
044c393e92
commit
8160d9915d
|
@ -28,18 +28,30 @@ pub fn start_app(server_sender: SP) -> Result<()> {
|
|||
))
|
||||
.unwrap();
|
||||
let config_path = Path::new(".hole.toml");
|
||||
match File::open(&config_path) {
|
||||
Err(e) => {
|
||||
log::debug!("creating new config file...");
|
||||
// std::fs::File::create(&config_path).unwrap();
|
||||
server_sender.send(PackedMessage::ToFreenet(
|
||||
fcpv2::client::fcp_types::GenerateSSK {
|
||||
identifier: Some("config-SSK".to_string()),
|
||||
}
|
||||
.convert()
|
||||
)).unwrap()}
|
||||
,
|
||||
Ok(res) => {} // TODO converting file from TOML to JSON and sending it to frontend
|
||||
match File::open(&config_path) {
|
||||
Err(e) => {
|
||||
log::debug!("creating new config file...");
|
||||
// std::fs::File::create(&config_path).unwrap();
|
||||
server_sender
|
||||
.send(PackedMessage::ToFreenet(
|
||||
fcpv2::client::fcp_types::GenerateSSK {
|
||||
identifier: Some("config-SSK".to_string()),
|
||||
}
|
||||
.convert(),
|
||||
))
|
||||
.unwrap()
|
||||
}
|
||||
Ok(res) => {
|
||||
let conf = std::fs::read_to_string(&config_path).unwrap();
|
||||
log::debug!("Responsing to start_app: {}", &conf);
|
||||
let toml: crate::chat::Config = toml::from_str(&conf[..]).unwrap();
|
||||
server_sender
|
||||
.send(PackedMessage::ToClient(
|
||||
serde_json::to_string(&toml).unwrap(),
|
||||
))
|
||||
.unwrap();
|
||||
log::debug!("Responsing to start_app");
|
||||
} // TODO converting file from TOML to JSON and sending it to frontend
|
||||
};
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -95,8 +95,9 @@ async fn connection_for_receiving(
|
|||
// log::debug!("they are different");
|
||||
match res {
|
||||
PackedMessage::FromCore(json) => {
|
||||
async_std::task::block_on(sender.send(Message::Text(json)))
|
||||
.expect("Couldn't send message")
|
||||
async_std::task::block_on(sender.send(Message::Text(json.clone())))
|
||||
.expect("Couldn't send message");
|
||||
log::debug!("Message sended to frontend: {}", json.clone());
|
||||
}
|
||||
PackedMessage::FromFreenet(response) => {
|
||||
let r = response.clone();
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::io::prelude::*;
|
|||
use std::path::Path;
|
||||
use async_std::io;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
#[derive(Deserialize, Serialize, Clone, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Config {
|
||||
pub id: crate::db::types::Id,
|
||||
|
|
|
@ -3,6 +3,8 @@ use async_std::io;
|
|||
use fcpv2::client::fcp_types::ClientGet;
|
||||
use fcpv2::types::{traits::FcpRequest, ReturnType, KEY, SSK, USK};
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::path::Path;
|
||||
use std::fs::File;
|
||||
|
||||
type SP = Sender<PackedMessage>;
|
||||
|
||||
|
@ -12,6 +14,11 @@ pub async fn request_repeater(ss: SP) -> io::Result<()> {
|
|||
// loop {
|
||||
//TODO create a field with tracked users
|
||||
log::debug!("Request Repeater Started!");
|
||||
let config: String = String::from_utf8_lossy(&std::fs::read(".hole.toml")?).parse().unwrap();
|
||||
let parsed: crate::chat::Config = toml::from_str(&config[..]).unwrap();
|
||||
|
||||
log::debug!("Config gotted: {:?}", &config);
|
||||
|
||||
loop {
|
||||
let users: Vec<crate::db::types::User> = crate::db::users::load_all_users(&db).unwrap();
|
||||
let time = std::time::Duration::from_millis(1300);
|
||||
|
@ -25,7 +32,7 @@ pub async fn request_repeater(ss: SP) -> io::Result<()> {
|
|||
ClientGet::new_default(
|
||||
KEY::USK(
|
||||
USK {
|
||||
ssk: user.insert_key,
|
||||
ssk: parsed.private_key.clone(),
|
||||
path: format!("{}/{}", &id, &index),
|
||||
}
|
||||
),
|
||||
|
|
|
@ -16,7 +16,7 @@ pub type Time = chrono::DateTime<chrono::Local>;
|
|||
|
||||
pub type SignKey = String;
|
||||
pub type InsertKey = SSK;
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq)]
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]
|
||||
pub struct Id(pub uuid::Uuid);
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
|
|
Loading…
Reference in a new issue