Skip to content

Commit

Permalink
feat(processor): init basic pdf content generate
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jan 4, 2022
1 parent e8088c6 commit 70f2c83
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ keywords = ["knowledge", "dashboard"]
[dependencies]
quake_core = { path = "quake_core", version = "0.3.0" }
quake_tui = { path = "quake_tui", version = "0.3.0" }
quake_processor = { path = "libs/quake_processor", version = "0.3.0" }

# cli parser
clap = { version = "3.0.0-beta.5", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/papers/0002-workflow-engine-spike.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: workflow engine spike
file: docs/Presto_SQL_on_Everything.pdf
file: pdca/Presto_SQL_on_Everything.pdf
created_date: 2021-12-30 21:21:25
updated_date: 2021-12-30 21:21:25
---
2 changes: 1 addition & 1 deletion examples/papers/entries.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"id","title","file","created_date","updated_date"
1,"A System for Query, Analysis and Visualization of Multi-dimensional Relational Databases","pdca/polaris.pdf","2021-12-30 21:11:19","2021-12-30 21:11:19"
2,"workflow engine spike","docs/workflows.md","2021-12-30 21:21:25","2021-12-30 21:21:25"
2,"workflow engine spike",docs/Presto_SQL_on_Everything.pdf,"2021-12-30 21:21:25","2021-12-30 21:21:25"
2 changes: 1 addition & 1 deletion libs/quake_processor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quake_processor"
version = "0.1.0"
version = "0.3.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
1 change: 1 addition & 0 deletions quake_core/src/meta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl EntryDefineProperties {
"title" => MetaProperty::Title(value),
"flow" => MetaProperty::Flow(value),
"string" => MetaProperty::Text(value),
"file" => MetaProperty::File(value),
"searchable" => MetaProperty::Searchable("string".to_string()),
"filterable" => MetaProperty::Filterable("string".to_string()),
"date" => MetaProperty::Date(value),
Expand Down
66 changes: 55 additions & 11 deletions src/cli/entry_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ use std::fs::File;
use std::path::Path;

use tracing::info;
use walkdir::WalkDir;

use quake_core::entry::entry_file::EntryFile;
use quake_core::entry::entry_paths::EntryPaths;
use quake_core::entry::EntryDefines;
use quake_core::entry::{EntryDefine, EntryDefines};
use quake_core::errors::QuakeError;
use quake_core::meta::MetaProperty;
use quake_core::parser::quake::QuakeActionNode;
use quake_core::quake_config::QuakeConfig;
use quake_core::usecases::entry_usecases;
use quake_core::usecases::entry_usecases::find_entry_path;
use quake_core::usecases::entrysets::Entrysets;
use quake_processor::process_engine::ProcessEngine;

use crate::cli::helper::table_process;
use crate::helper::exec_wrapper::{editor_exec, meili_exec};
Expand Down Expand Up @@ -78,7 +81,7 @@ pub fn entry_action(expr: &QuakeActionNode, conf: QuakeConfig) -> Result<(), Box
}
}
"generate" => {
generate_content(&paths);
generate_content(&paths, &expr.entry)?;
}
"sync" => entry_usecases::sync_in_path(&paths)?,
"feed" => feed_by_path(&paths, &expr.entry, &conf)?,
Expand Down Expand Up @@ -166,20 +169,60 @@ pub fn dump_by_path(paths: &EntryPaths) -> Result<(), Box<dyn Error>> {
Ok(())
}

fn generate_content(paths: &EntryPaths) {
fn generate_content(paths: &EntryPaths, entry: &str) -> Result<(), Box<dyn Error>> {
let defines = EntryDefines::from_path(&paths.entries_define);
for define in &defines.entries {
if define.processors.is_none() {
continue;
match defines.find(entry) {
None => {}
Some(define) => generate_by_path(paths, &define)?,
}

Ok(())
}

fn generate_by_path(paths: &EntryPaths, define: &EntryDefine) -> Result<(), Box<dyn Error>> {
let mut field = "".to_string();
for (typ, property) in define.to_field_type() {
if let MetaProperty::File(_file) = property {
field = typ
}
}

if field.is_empty() {
return Err(Box::new(QuakeError("cannot find entry".to_string())));
}

let file_engines = &define.processors.as_ref().unwrap().file_engines;
if let Some(engines) = file_engines {
for engine in engines {
println!("{:}", engine);
let walk_paths = WalkDir::new(&paths.entry_path)
.max_depth(1)
.min_depth(1)
.into_iter()
.filter_map(|e| e.ok());

for path in walk_paths {
let name = path.file_name().to_str().unwrap();
if EntryFile::is_match(name) {
let content = fs::read_to_string(path.path())?;
let entry_file = EntryFile::from(&*content, 1)?;
match entry_file.property(&field) {
None => {}
Some(value) => {
let file_path = paths.entry_path.join(value);
if file_path.exists() {
let ext = file_path.extension().unwrap().to_str().unwrap();
let engine = ProcessEngine::engine(ext);
let content = engine.content(&file_path)?;

println!("call {:?} engine from {:?}", ext, file_path);

println!("{:?}", content);
} else {
return Err(Box::new(QuakeError("cannot entry file".to_string())));
}
}
}
}
}

Ok(())
}

#[cfg(test)]
Expand All @@ -189,9 +232,10 @@ mod tests {

use crate::cli::entry_action::entry_action;

#[ignore]
#[test]
fn test_generate_content_for_processors() {
let expr = QuakeActionNode::from_text("todo.generate").unwrap();
let expr = QuakeActionNode::from_text("papers.generate").unwrap();
let config = QuakeConfig {
editor: "".to_string(),
workspace: "examples".to_string(),
Expand Down
1 change: 1 addition & 0 deletions src/cli/helper/content_process.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub struct FileContentProcess {}
1 change: 1 addition & 0 deletions src/cli/helper/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod content_process;
pub mod table_process;

0 comments on commit 70f2c83

Please sign in to comment.