Commit 14e70140 authored by Stavros Korokithakis's avatar Stavros Korokithakis

Merge branch 'tcyrus-master-patch-18095' into 'master'

Simplify Code

See merge request !1
parents a919e42e cf215974
Pipeline #120680541 failed with stage
in 3 minutes and 9 seconds
#[macro_use]
extern crate clap;
#[macro_use]
extern crate lazy_static;
......@@ -13,7 +14,6 @@ extern crate xdg;
mod views;
use clap::{App, Arg};
use log::Level;
use notify::{RecommendedWatcher, RecursiveMode, Watcher};
use std::collections::HashMap;
......@@ -22,8 +22,7 @@ use std::ffi::OsStr;
use std::fs;
use std::io;
use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream};
use std::process;
use std::process::Command;
use std::process::{self, Command};
use std::sync::mpsc::channel;
use std::sync::Mutex;
use std::thread;
......@@ -134,8 +133,7 @@ fn notify_eternum() {
debug!("Notifying Eternum with hash {}...", hash);
let mut payload = HashMap::new();
payload.insert("site_hash", hash);
let payload: HashMap<&str, _> = [("site_hash", hash)].iter().cloned().collect();
let eternum_url = format!("https://www.eternum.io/api/site/?key={}", eternum_key);
let client = reqwest::Client::new();
......@@ -153,10 +151,10 @@ fn notify_ipfs(fs_event: bool) {
let mut last_event_time = LAST_EVENT_TIME.lock().unwrap();
debug!("Got event, fs_event={:?}", fs_event);
if last_event_time.is_none() {
debug!("Last event time is None");
} else {
debug!("Last event time is {:?}", last_event_time.unwrap());
match last_event_time {
None => debug!("Last event time is None"),
Some(t) => debug!("Last event time is {:?}", t),
}
if fs_event {
......@@ -294,12 +292,13 @@ fn cron_thread() {
/// Handle the inotify events in the Hearth directory.
fn files_changed(op: notify::Op, path: std::path::PathBuf) {
debug!("Got new event: {:?}, {:?}", op, path);
if op.contains(notify::op::CREATE)
|| op.contains(notify::op::REMOVE)
|| op.contains(notify::op::RENAME)
|| op.contains(notify::op::WRITE)
|| op.contains(notify::op::RESCAN)
|| op.contains(notify::op::CLOSE_WRITE)
if op.intersects(
notify::op::CREATE |
notify::op::REMOVE |
notify::op::RENAME |
notify::op::WRITE |
notify::op::RESCAN |
notify::op::CLOSE_WRITE)
{
notify_ipfs(true);
}
......@@ -343,30 +342,20 @@ fn ping_eternum() {
}
fn main() {
let matches = App::new("Hearth")
.author("by Stavros and Stelios")
.about("A personal website publisher")
.arg(
Arg::with_name("eternum_key")
.short("k")
.long("api_key")
.value_name("APIKEY")
.help("Your Eternum API key, to automatically update your personal site hash")
.takes_value(true),
)
.arg(
Arg::with_name("debug")
.short("d")
.long("debug")
.help("Print debugging information"),
)
.get_matches();
if matches.is_present("debug") {
simple_logger::init_with_level(Level::Debug).unwrap();
} else {
simple_logger::init_with_level(Level::Info).unwrap();
}
let matches = clap_app!(Hearth =>
(author: "by Stavros and Stelios")
(about: "A personal website publisher")
(@arg eternum_key: -k --api_key <APIKEY> +takes_value "Your Eternum API key, to automatically update your personal site hash")
(@arg debug: -d --debug "Print debugging information")
).get_matches();
simple_logger::init_with_level(
if matches.is_present("debug") {
Level::Debug
} else {
Level::Info
}
).unwrap();
{
let mut eternum_key = ETERNUM_KEY.lock().unwrap();
......
......@@ -28,11 +28,13 @@ pub fn start_api() {
let path = request.get_param("path").unwrap_or("".to_string());
let hashes = IPFS_HASHES.lock().unwrap();
if hashes.contains_key(&path) {
let hash = hashes.get(&path).unwrap();
Response::json(&HashResponse{hash: hash.to_string(), path: path.to_string(), result: "ok".to_owned()})
} else {
Response::empty_404()
match hashes.get(&path) {
Some(hash) => Response::json(&HashResponse{
hash: hash.to_string(),
path: path.to_string(),
result: "ok".to_owned()
}),
None => Response::empty_404(),
}
},
_ => rouille::Response::empty_404()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment