diff --git a/.idea/readwise-bulk-upload.iml b/.idea/readwise-bulk-upload.iml index cc58e9c..cf84ae4 100644 --- a/.idea/readwise-bulk-upload.iml +++ b/.idea/readwise-bulk-upload.iml @@ -2,9 +2,7 @@ - - - + diff --git a/Cargo.lock b/Cargo.lock index 5daa196..dfdfe03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -279,27 +279,6 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" -[[package]] -name = "cli" -version = "0.1.0" -dependencies = [ - "chrono", - "clap", - "directories", - "figment", - "futures", - "lib_sync_core", - "serde", - "serde_json", - "sqlx", - "tabled", - "thiserror", - "tokio", - "tracing", - "tracing-core", - "tracing-subscriber", -] - [[package]] name = "colorchoice" version = "1.0.3" @@ -937,26 +916,6 @@ dependencies = [ "spin", ] -[[package]] -name = "lib_sync_core" -version = "0.1.0" -dependencies = [ - "chrono", - "clap", - "directories", - "figment", - "futures", - "serde", - "serde_json", - "sqlx", - "tabled", - "thiserror", - "tokio", - "tracing", - "tracing-core", - "tracing-subscriber", -] - [[package]] name = "libc" version = "0.2.172" @@ -1362,6 +1321,26 @@ dependencies = [ "getrandom 0.2.16", ] +[[package]] +name = "readwise-bulk-upload" +version = "0.1.0" +dependencies = [ + "chrono", + "clap", + "directories", + "figment", + "futures", + "serde", + "serde_json", + "sqlx", + "tabled", + "thiserror", + "tokio", + "tracing", + "tracing-core", + "tracing-subscriber", +] + [[package]] name = "redox_syscall" version = "0.5.12" @@ -2240,10 +2219,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "web" -version = "0.1.0" - [[package]] name = "whoami" version = "1.6.0" diff --git a/Cargo.toml b/Cargo.toml index df1befe..3f51301 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,20 @@ -[workspace] -resolver = "3" +[package] +name = "readwise-bulk-upload" +version = "0.1.0" +edition = "2024" -members = [ - "cli", "lib_sync_core", "web", -] +[dependencies] +thiserror = "2.0.12" +directories = "6.0.0" +tokio = { version = "1.45.0", features = ["default", "rt", "rt-multi-thread", "macros"] } +sqlx = { version = "0.8", features = [ "runtime-tokio", "sqlite", "chrono", "migrate" ] } +clap = { version = "4.5.37", features = ["derive"] } +serde = { version = "1.0.219", features = ["derive"] } +chrono = {version = "0.4.41", features = ["serde"]} +serde_json = "1.0.140" +tracing = "0.1.41" +tracing-subscriber = { version = "0.3.19" , features = ["env-filter"]} +figment = { version = "0.10.19", features = ["env"] } +tracing-core = "0.1.33" +tabled = "0.19.0" +futures = "0.3.31" \ No newline at end of file diff --git a/cli/Cargo.toml b/cli/Cargo.toml deleted file mode 100644 index c056a52..0000000 --- a/cli/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "cli" -version = "0.1.0" -edition = "2024" - -[[bin]] -name = "readwise" -path = "bin/readwise/main.rs" - -[dependencies] -lib_sync_core = {path = "../lib_sync_core"} - -directories = "6.0.0" -tokio = { version = "1.45.0", features = ["default", "rt", "rt-multi-thread", "macros"] } -sqlx = { version = "0.8", features = [ "runtime-tokio", "sqlite", "chrono", "migrate" ] } -clap = { version = "4.5.37", features = ["derive"] } -serde = { version = "1.0.219", features = ["derive"] } -chrono = {version = "0.4.41", features = ["serde"]} -serde_json = "1.0.140" -tracing = "0.1.41" -tracing-subscriber = { version = "0.3.19" , features = ["env-filter"]} -figment = { version = "0.10.19", features = ["env"] } -tracing-core = "0.1.33" -tabled = "0.19.0" -futures = "0.3.31" -thiserror = "2.0.12" \ No newline at end of file diff --git a/cli/src/main.rs b/cli/src/main.rs deleted file mode 100644 index 75c0be7..0000000 --- a/cli/src/main.rs +++ /dev/null @@ -1,23 +0,0 @@ -use clap::Parser; -use figment::{ - providers::{Env, Serialized}, - Figment, -}; -use cli::config::Config; -use cli::Result; -use tracing_subscriber; - -#[tokio::main] -async fn main() -> Result<()> { - let cli = Config::parse(); - let args: Config = Figment::new() - .merge(Serialized::defaults(&cli)) - .merge(Env::prefixed("APP_")) - .extract()?; - - tracing_subscriber::fmt() - .with_max_level(args.log_level()) - .init(); - - Ok(()) -} diff --git a/lib_sync_core/Cargo.toml b/lib_sync_core/Cargo.toml deleted file mode 100644 index c6d73f7..0000000 --- a/lib_sync_core/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "lib_sync_core" -version = "0.1.0" -edition = "2024" - -[dependencies] -directories = "6.0.0" -tokio = { version = "1.45.0", features = ["default", "rt", "rt-multi-thread", "macros"] } -sqlx = { version = "0.8", features = [ "runtime-tokio", "sqlite", "chrono", "migrate" ] } -clap = { version = "4.5.37", features = ["derive"] } -serde = { version = "1.0.219", features = ["derive"] } -chrono = {version = "0.4.41", features = ["serde"]} -serde_json = "1.0.140" -tracing = "0.1.41" -tracing-subscriber = { version = "0.3.19" , features = ["env-filter"]} -figment = { version = "0.10.19", features = ["env"] } -tracing-core = "0.1.33" -tabled = "0.19.0" -futures = "0.3.31" -thiserror = "2.0.12" diff --git a/lib_sync_core/src/error.rs b/lib_sync_core/src/error.rs deleted file mode 100644 index 93c8a0b..0000000 --- a/lib_sync_core/src/error.rs +++ /dev/null @@ -1,24 +0,0 @@ -use thiserror::Error; - -#[derive(Error, Debug)] -pub enum Error { - #[error("{0}")] - Exception(&'static str), - - #[error("{0}")] - Unhandled(&'static str), - - #[error(transparent)] - Io(#[from] tokio::io::Error), - - #[error(transparent)] - Sqlx(#[from] sqlx::Error), - - #[error(transparent)] - Migration(#[from] sqlx::migrate::MigrateError), - - #[error(transparent)] - ParseJson(#[from] serde_json::Error), -} - -pub type Result = std::result::Result; \ No newline at end of file diff --git a/lib_sync_core/src/lib.rs b/lib_sync_core/src/lib.rs deleted file mode 100644 index 810ba8e..0000000 --- a/lib_sync_core/src/lib.rs +++ /dev/null @@ -1,19 +0,0 @@ -pub mod error; - -pub(crate) use error::*; -pub mod task_manager; - -pub fn add(left: u64, right: u64) -> u64 { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} diff --git a/cli/src/config.rs b/src/config.rs similarity index 100% rename from cli/src/config.rs rename to src/config.rs diff --git a/cli/src/error.rs b/src/error.rs similarity index 88% rename from cli/src/error.rs rename to src/error.rs index 36572b2..b55b32e 100644 --- a/cli/src/error.rs +++ b/src/error.rs @@ -11,9 +11,6 @@ pub enum Error { #[error("{0}")] Unhandled(&'static str), - #[error(transparent)] - Sync(#[from] lib_sync_core::error::Error), - #[error(transparent)] Sqlx(#[from] sqlx::Error), diff --git a/cli/src/lib.rs b/src/lib.rs similarity index 52% rename from cli/src/lib.rs rename to src/lib.rs index dabf39f..f63d5eb 100644 --- a/cli/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,6 @@ -pub mod config; mod error; +pub mod task_manager; +pub mod config; +pub mod readwise; pub use error::*; \ No newline at end of file diff --git a/cli/bin/readwise/main.rs b/src/main.rs similarity index 59% rename from cli/bin/readwise/main.rs rename to src/main.rs index bdfc584..ff1f2ac 100644 --- a/cli/bin/readwise/main.rs +++ b/src/main.rs @@ -1,18 +1,15 @@ use clap::{CommandFactory, Parser}; -use directories::ProjectDirs; use figment::{ - Figment, providers::{Env, Serialized}, + Figment, }; -use lib_sync_core::task_manager::{TaskManager, TaskStatus}; -use cli::config::{Command, Config}; -use cli::{Error, Result}; +use readwise_bulk_upload::config::{Command, Config}; +use readwise_bulk_upload::readwise::DocumentPayload; +use readwise_bulk_upload::task_manager::{TaskManager, TaskStatus}; +use readwise_bulk_upload::{Error, Result}; use std::fs::File; use tabled::Table; use tracing_subscriber; -use crate::external_interface::DocumentPayload; - -mod external_interface; #[tokio::main] async fn main() -> Result<()> { @@ -32,12 +29,7 @@ async fn main() -> Result<()> { } async fn run(command: &Command) -> Result<()> { - let project_dir = ProjectDirs::from("", "", "synchronizator_readwise").ok_or( - lib_sync_core::error::Error::Unhandled("Could not get standard directories"), - )?; - - let task_manager = TaskManager::new(project_dir.data_dir()).await?; - + let task_manager = TaskManager::new().await?; match command { Command::LoadTasks { path } => { let file = File::open(path).map_err(|_| { @@ -49,23 +41,20 @@ async fn run(command: &Command) -> Result<()> { let documents: Vec = serde_json::from_reader(file)?; + task_manager.load_tasks(documents).await?; } Command::Query => { - let tasks = task_manager - .get_tasks::(None, Some(25)) - .await?; + let tasks = task_manager.get_tasks::(None, Some(25)).await?; println!("{}", Table::new(tasks)); } Command::Run => { - task_manager - .run_tasks::(|task| { - println!("{}", task.get_key()); - - TaskStatus::Completed - }) - .await?; + task_manager.run_tasks::(|task| { + println!("{}", task.get_key()); + + TaskStatus::Completed + }).await?; } Command::None => { Config::command().print_help()?; diff --git a/cli/bin/readwise/external_interface.rs b/src/readwise.rs similarity index 96% rename from cli/bin/readwise/external_interface.rs rename to src/readwise.rs index 13b2f65..e3d7a42 100644 --- a/cli/bin/readwise/external_interface.rs +++ b/src/readwise.rs @@ -1,4 +1,4 @@ -use lib_sync_core::task_manager::TaskPayload; +use crate::task_manager::TaskPayload; use chrono::{DateTime, Local}; use serde::{de, Deserialize, Deserializer, Serialize}; use serde_json::Value; diff --git a/lib_sync_core/src/task_manager.rs b/src/task_manager.rs similarity index 89% rename from lib_sync_core/src/task_manager.rs rename to src/task_manager.rs index 57a2556..11401e2 100644 --- a/lib_sync_core/src/task_manager.rs +++ b/src/task_manager.rs @@ -1,4 +1,4 @@ -use crate::error::Error; +use crate::Error; use chrono::Utc; use directories::ProjectDirs; use futures::{StreamExt, TryStreamExt}; @@ -7,7 +7,6 @@ use serde::Serialize; use sqlx::sqlite::{SqliteConnectOptions, SqliteJournalMode}; use sqlx::{QueryBuilder, Sqlite, SqlitePool}; use std::fmt::Display; -use std::path::PathBuf; use tabled::Tabled; use tokio::fs; use tracing::{info, instrument}; @@ -80,26 +79,23 @@ impl _Task for T {} #[derive(Debug)] pub struct TaskManager { - base_path: PathBuf, pool: SqlitePool, } impl TaskManager { - pub async fn new>(base_path: P) -> Result { - let base_path = base_path.into(); - let pool = Self::connect_database(base_path.clone()).await?; + pub async fn new() -> Result { Ok(Self { - base_path, - pool, + pool: Self::connect_database().await?, }) } - async fn connect_database>(base_path: P) -> crate::Result { - let base_path = base_path.into(); + async fn connect_database() -> crate::Result { + let project_dir = ProjectDirs::from("", "", env!("CARGO_PKG_NAME")) + .ok_or(Error::Unhandled("Could not get standard directories"))?; - let database_file_path = base_path.join("db.sql"); + let database_file_path = project_dir.data_dir().join("db.sql"); - fs::create_dir_all(base_path).await?; + fs::create_dir_all(project_dir.data_dir()).await?; let opts = SqliteConnectOptions::new() .filename(database_file_path) @@ -108,7 +104,7 @@ impl TaskManager { let pool = SqlitePool::connect_with(opts).await?; - sqlx::migrate!("../migrations").run(&pool).await?; + sqlx::migrate!("./migrations").run(&pool).await?; Ok(pool) } diff --git a/web/Cargo.toml b/web/Cargo.toml deleted file mode 100644 index 52dfac4..0000000 --- a/web/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "web" -version = "0.1.0" -edition = "2024" - -[dependencies] diff --git a/web/src/main.rs b/web/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/web/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -}