aboutsummaryrefslogtreecommitdiffstats
path: root/src/local
diff options
context:
space:
mode:
authorEllie Huxtable <e@elm.sh>2021-04-20 21:53:07 +0100
committerGitHub <noreply@github.com>2021-04-20 20:53:07 +0000
commita21737e2b7f8d1e426726bdd7536033f299d476a (patch)
treee940afdff9c145d25d9a2895fd44a77d70719a2e /src/local
parentSwitch to Warp + SQLx, use async, switch to Rust stable (#36) (diff)
downloadatuin-a21737e2b7f8d1e426726bdd7536033f299d476a.zip
Use cargo workspaces (#37)
* Switch to Cargo workspaces Breaking things into "client", "server" and "common" makes managing the codebase much easier! client - anything running on a user's machine for adding history server - handles storing/syncing history and running a HTTP server common - request/response API definitions, common utils, etc * Update dockerfile
Diffstat (limited to '')
-rw-r--r--atuin-client/src/api_client.rs (renamed from src/local/api_client.rs)9
-rw-r--r--atuin-client/src/database.rs (renamed from src/local/database.rs)0
-rw-r--r--atuin-client/src/encryption.rs (renamed from src/local/encryption.rs)4
-rw-r--r--atuin-client/src/history.rs (renamed from src/local/history.rs)2
-rw-r--r--atuin-client/src/import.rs (renamed from src/local/import.rs)0
-rw-r--r--atuin-client/src/lib.rs (renamed from src/local/mod.rs)7
-rw-r--r--atuin-client/src/sync.rs (renamed from src/local/sync.rs)19
7 files changed, 25 insertions, 16 deletions
diff --git a/src/local/api_client.rs b/atuin-client/src/api_client.rs
index 1b64a295..db2802c3 100644
--- a/src/local/api_client.rs
+++ b/atuin-client/src/api_client.rs
@@ -4,10 +4,11 @@ use reqwest::header::{HeaderMap, AUTHORIZATION};
use reqwest::Url;
use sodiumoxide::crypto::secretbox;
-use crate::api::{AddHistoryRequest, CountResponse, SyncHistoryResponse};
-use crate::local::encryption::decrypt;
-use crate::local::history::History;
-use crate::utils::hash_str;
+use atuin_common::api::{AddHistoryRequest, CountResponse, SyncHistoryResponse};
+use atuin_common::utils::hash_str;
+
+use crate::encryption::decrypt;
+use crate::history::History;
pub struct Client<'a> {
sync_addr: &'a str,
diff --git a/src/local/database.rs b/atuin-client/src/database.rs
index abc22bb8..abc22bb8 100644
--- a/src/local/database.rs
+++ b/atuin-client/src/database.rs
diff --git a/src/local/encryption.rs b/atuin-client/src/encryption.rs
index 3c1699e3..37153f94 100644
--- a/src/local/encryption.rs
+++ b/atuin-client/src/encryption.rs
@@ -15,7 +15,7 @@ use std::path::PathBuf;
use eyre::{eyre, Result};
use sodiumoxide::crypto::secretbox;
-use crate::local::history::History;
+use crate::history::History;
use crate::settings::Settings;
#[derive(Debug, Serialize, Deserialize)]
@@ -26,7 +26,7 @@ pub struct EncryptedHistory {
// Loads the secret key, will create + save if it doesn't exist
pub fn load_key(settings: &Settings) -> Result<secretbox::Key> {
- let path = settings.local.key_path.as_str();
+ let path = settings.key_path.as_str();
if PathBuf::from(path).exists() {
let bytes = std::fs::read(path)?;
diff --git a/src/local/history.rs b/atuin-client/src/history.rs
index 1712f8b9..7f607784 100644
--- a/src/local/history.rs
+++ b/atuin-client/src/history.rs
@@ -3,7 +3,7 @@ use std::hash::{Hash, Hasher};
use chrono::Utc;
-use crate::command::uuid_v4;
+use atuin_common::utils::uuid_v4;
// Any new fields MUST be Optional<>!
#[derive(Debug, Clone, Serialize, Deserialize)]
diff --git a/src/local/import.rs b/atuin-client/src/import.rs
index 3b0b2a69..3b0b2a69 100644
--- a/src/local/import.rs
+++ b/atuin-client/src/import.rs
diff --git a/src/local/mod.rs b/atuin-client/src/lib.rs
index 9fe31292..1207bfdb 100644
--- a/src/local/mod.rs
+++ b/atuin-client/src/lib.rs
@@ -1,6 +1,13 @@
+#[macro_use]
+extern crate log;
+
+#[macro_use]
+extern crate serde_derive;
+
pub mod api_client;
pub mod database;
pub mod encryption;
pub mod history;
pub mod import;
+pub mod settings;
pub mod sync;
diff --git a/src/local/sync.rs b/atuin-client/src/sync.rs
index e0feb759..0ca8d3a6 100644
--- a/src/local/sync.rs
+++ b/atuin-client/src/sync.rs
@@ -3,11 +3,12 @@ use std::convert::TryInto;
use chrono::prelude::*;
use eyre::Result;
-use crate::local::api_client;
-use crate::local::database::Database;
-use crate::local::encryption::{encrypt, load_key};
-use crate::settings::{Local, Settings, HISTORY_PAGE_SIZE};
-use crate::{api::AddHistoryRequest, utils::hash_str};
+use atuin_common::{api::AddHistoryRequest, utils::hash_str};
+
+use crate::api_client;
+use crate::database::Database;
+use crate::encryption::{encrypt, load_key};
+use crate::settings::{Settings, HISTORY_PAGE_SIZE};
// Currently sync is kinda naive, and basically just pages backwards through
// history. This means newly added stuff shows up properly! We also just use
@@ -33,7 +34,7 @@ async fn sync_download(
let mut last_sync = if force {
Utc.timestamp_millis(0)
} else {
- Local::last_sync()?
+ Settings::last_sync()?
};
let mut last_timestamp = Utc.timestamp_millis(0);
@@ -124,8 +125,8 @@ async fn sync_upload(
pub async fn sync(settings: &Settings, force: bool, db: &mut (impl Database + Send)) -> Result<()> {
let client = api_client::Client::new(
- settings.local.sync_address.as_str(),
- settings.local.session_token.as_str(),
+ settings.sync_address.as_str(),
+ settings.session_token.as_str(),
load_key(settings)?,
);
@@ -135,7 +136,7 @@ pub async fn sync(settings: &Settings, force: bool, db: &mut (impl Database + Se
debug!("sync downloaded {}", download.0);
- Local::save_sync_time()?;
+ Settings::save_sync_time()?;
Ok(())
}