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