diff --git a/Cargo.lock b/Cargo.lock index cd05612..e731a1f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -385,6 +385,8 @@ dependencies = [ "kasuku-database", "notify", "plugy", + "pulldown-cmark", + "pulldown-cmark-to-cmark", "serde", "serde_json", "tokio", @@ -2625,6 +2627,15 @@ dependencies = [ "unicase", ] +[[package]] +name = "pulldown-cmark-to-cmark" +version = "11.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a883e495f8fc4f209521b03a89dde6f6f211ed7cf92e85693c82508e8b722710" +dependencies = [ + "pulldown-cmark", +] + [[package]] name = "quote" version = "0.6.13" diff --git a/Kasuku.toml b/Kasuku.toml index e1bb496..1a5d9e3 100644 --- a/Kasuku.toml +++ b/Kasuku.toml @@ -1,7 +1,8 @@ [internals] -cache-path = "./cache" +cache-path = "/tmp/kasuku-cache" [vaults.planning] +label = "Planning" plugins = ["tasks"] mount = "/home/geoff/Documents/kasuku" file_types = ["md"] diff --git a/crates/backend/Cargo.toml b/crates/backend/Cargo.toml index 9e0fcbc..7eafcc7 100644 --- a/crates/backend/Cargo.toml +++ b/crates/backend/Cargo.toml @@ -31,3 +31,5 @@ xtra = { git = "https://github.com/Restioson/xtra", features = [ "macros", ] } futures = "0.3" +pulldown-cmark-to-cmark = "11.0.2" +pulldown-cmark = { version = "0.9.3" } diff --git a/crates/backend/src/lib.rs b/crates/backend/src/lib.rs index a9e94ae..212a618 100644 --- a/crates/backend/src/lib.rs +++ b/crates/backend/src/lib.rs @@ -60,7 +60,30 @@ impl KasukuRuntime { res.unwrap() }) .await; - let db = Glue::new(ks); + let mut db = Glue::new(ks); + db.execute( + " + DROP TABLE subscriptions; + DROP TABLE vaults; + DROP TABLE entries; + CREATE TABLE IF NOT EXISTS subscriptions ( + plugin TEXT NOT NULL, + event TEXT NOT NULL, + event_type TEXT NOT NULL, + data TEXT + ); + CREATE TABLE IF NOT EXISTS vaults ( + name TEXT NOT NULL PRIMARY KEY, + mount TEXT NOT NULL, + ); + CREATE TABLE IF NOT EXISTS entries ( + path TEXT NOT NULL PRIMARY KEY, + vault TEXT NOT NULL, + last_modified INTEGER, + meta TEXT + )", + ) + .unwrap(); let db = Arc::new(Mutex::new(db)); let runtime = Runtime::new().unwrap(); @@ -76,23 +99,6 @@ impl KasukuRuntime { .unwrap(); plugin.on_load(::types::Context::acquire()).await.unwrap(); } - // db.lock().unwrap().storage.save().await.unwrap(); - db.lock() - .as_mut() - .unwrap() - .execute( - "CREATE TABLE IF NOT EXISTS vaults ( - name TEXT NOT NULL PRIMARY KEY, - mount TEXT NOT NULL, - ); - CREATE TABLE IF NOT EXISTS entries ( - path TEXT NOT NULL PRIMARY KEY, - vault TEXT NOT NULL, - last_modified INTEGER, - meta TEXT - )", - ) - .unwrap(); for (vault, vault_config) in config.vaults.clone() { let mount = vault_config.mount.clone(); @@ -105,8 +111,7 @@ impl KasukuRuntime { "INSERT INTO vaults(name, mount) VALUES ('{vault}', '{}') ON CONFLICT(name) DO UPDATE SET mount = EXCLUDED.mount", mount.to_str().unwrap() - )) - .unwrap_or(vec![]); + )); // tokio::spawn(async move { use futures::stream::StreamExt; @@ -130,7 +135,6 @@ impl KasukuRuntime { loop { match entries.next().await { Some(Ok(entry)) => { - println!("file: {}", entry.path().display()); let _res = db.lock().unwrap().execute(format!( "INSERT INTO entries(path, vault) VALUES('{}', '{}')", entry.path().display(), @@ -177,11 +181,6 @@ pub async fn app(port: u16, data: D) { "/", get(graphiql).post_service(GraphQL::new(schema.clone())), ) - // .route( - // "/api/v1/:namespace/:plugin/*path", - // get(getter).post(do_action), - // ) - // .route("/api/v1/:namespace/:plugin", get(getter)) .layer(CorsLayer::new().allow_origin(Any).allow_methods(vec![ Method::GET, Method::POST, diff --git a/crates/backend/src/query.rs b/crates/backend/src/query.rs index 47b171f..93632f6 100644 --- a/crates/backend/src/query.rs +++ b/crates/backend/src/query.rs @@ -1,3 +1,4 @@ +use ::types::MarkdownEvent; use ::types::{Emit, Event}; use async_graphql::*; use kasuku_database::prelude::Payload; @@ -20,7 +21,7 @@ pub struct File { #[ComplexObject] impl File { - async fn render(&self, ctx: &Context<'_>, renderer: Option) -> serde_json::Value { + async fn preview(&self, ctx: &Context<'_>) -> serde_json::Value { let runtime: &KasukuRuntime = ctx.data().unwrap(); let plugin: ::types::PluginWrapper = runtime.get_plugin_by_name("tasks").unwrap(); @@ -49,10 +50,60 @@ impl QueryRoot { path: String, renderer: Option, ) -> serde_json::Value { - File { path } - .render(ctx, renderer) - .await + let runtime: &KasukuRuntime = ctx.data().unwrap(); + let res = runtime + .database + .lock() .unwrap() + .execute("SELECT * FROM subscriptions WHERE event = 'MarkdownEvent';") + .unwrap(); + let subscriptions = res.get(0).unwrap(); + match subscriptions { + Payload::Select { rows, .. } => { + let filters: Vec = rows + .iter() + .map(|row| match row.get(3).unwrap() { + kasuku_database::prelude::Value::Str(val) => { + serde_json::from_str(&val).unwrap() + } + _ => unreachable!(), + }) + .collect(); + let plugin: ::types::PluginWrapper = + runtime.get_plugin_by_name("tasks").unwrap(); + let mut md = ::types::File::read(&path).await.unwrap(); + md = plugin + .process_file(::types::Context::acquire(), md) + .await + .unwrap(); + let mut buf = String::new(); + let md_events: Vec> =match &md { + ::types::File::Markdown(inner) => inner.get_contents(), + _ => unreachable!(), + }; + pulldown_cmark_to_cmark::cmark(md_events.iter(), &mut buf).unwrap(); + println!("{buf}"); + + } + _ => unreachable!(), + }; + + let plugin: ::types::PluginWrapper = + runtime.get_plugin_by_name("tasks").unwrap(); + let res = plugin + .render( + ::types::Context::acquire(), + Event { + path, + data: Emit { + data: vec![], + r#type: "Event".to_string(), + }, + }, + ) + .await + .unwrap(); + serde_json::from_slice(&res.0).unwrap() } async fn vaults(&self, ctx: &Context<'_>) -> Vec { let runtime: &KasukuRuntime = ctx.data().unwrap(); diff --git a/crates/frontend/src/main.rs b/crates/frontend/src/main.rs index 8c84a58..1c16a65 100644 --- a/crates/frontend/src/main.rs +++ b/crates/frontend/src/main.rs @@ -1,22 +1,19 @@ +mod tab_view; + +use crate::tab_view::TabView; use hirola::dom::app::App; use hirola::dom::Dom; use hirola::prelude::*; #[component] fn Logo() -> Dom { - html! { -