Skip to content

Commit

Permalink
feat: parse json
Browse files Browse the repository at this point in the history
Signed-off-by: 117503445 <[email protected]>
  • Loading branch information
117503445 committed Oct 15, 2023
1 parent 96c1dbd commit 02cbd7a
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 1 deletion.
80 changes: 80 additions & 0 deletions src/fc-local-dev/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/fc-local-dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
notify = "6.1.1"
notify = "6.1.1"

serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
16 changes: 16 additions & 0 deletions src/fc-local-dev/rule.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"triggers": [
{
"prefix": "nougat/input",
"suffix": "pdf"
}
],
"actions": [
{
"type": "docker",
"args": {
"image": "117503445/flow-pdf-nougat"
}
}
]
}
31 changes: 31 additions & 0 deletions src/fc-local-dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,44 @@ use notify::{
event::{AccessKind, AccessMode},
Config, EventKind, RecommendedWatcher, RecursiveMode, Watcher,
};
use serde::Deserialize;
use std::io::Read;
use std::path::Path;
use std::{collections::HashMap, fs::File};

#[derive(Deserialize, Debug)]
#[allow(dead_code)]
struct Trigger {
prefix: String,
suffix: String,
}

#[derive(Deserialize, Debug)]
#[allow(dead_code)]
struct Action {
r#type: String,
args: HashMap<String, String>,
}

#[derive(Deserialize, Debug)]
#[allow(dead_code)]
struct Rule {
triggers: Vec<Trigger>,
actions: Vec<Action>,
}

fn main() {
// let path = std::env::args()
// .nth(1)
// .expect("Argument 1 needs to be a path");

let mut file = File::open("rule.json").expect("Failed to open rule.json");
let mut contents = String::new();
file.read_to_string(&mut contents)
.expect("Failed to read rule.json");
let rule: Rule = serde_json::from_str(&contents).expect("Failed to parse JSON");
println!("rule: {:?}", rule);

let path = "/data";

println!("Watching {path}");
Expand Down

0 comments on commit 02cbd7a

Please sign in to comment.