mirror of
https://github.com/atuinsh/atuin.git
synced 2025-02-17 19:01:22 +01:00
format, lint, add status command
This commit is contained in:
parent
5ae35b40db
commit
eadce83a57
@ -8,7 +8,7 @@ use reqwest::{
|
|||||||
StatusCode, Url,
|
StatusCode, Url,
|
||||||
};
|
};
|
||||||
|
|
||||||
use atuin_common::record::{EncryptedData, HostId, Record, RecordId, RecordIdx};
|
use atuin_common::record::{EncryptedData, HostId, Record, RecordIdx};
|
||||||
use atuin_common::{
|
use atuin_common::{
|
||||||
api::{
|
api::{
|
||||||
AddHistoryRequest, CountResponse, DeleteHistoryRequest, ErrorResponse, IndexResponse,
|
AddHistoryRequest, CountResponse, DeleteHistoryRequest, ErrorResponse, IndexResponse,
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
|
use rmp::decode::ValueReadError;
|
||||||
use rmp::decode::{ValueReadError};
|
|
||||||
use rmp::{decode::Bytes, Marker};
|
use rmp::{decode::Bytes, Marker};
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use atuin_common::record::{DecryptedData};
|
use atuin_common::record::DecryptedData;
|
||||||
use atuin_common::utils::uuid_v7;
|
use atuin_common::utils::uuid_v7;
|
||||||
|
|
||||||
use eyre::{bail, eyre, Result};
|
use eyre::{bail, eyre, Result};
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
|
|
||||||
|
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
use serde::{Serialize};
|
|
||||||
|
|
||||||
use crate::record::{encryption::PASETO_V4, sqlite_store::SqliteStore, store::Store};
|
use crate::record::{encryption::PASETO_V4, sqlite_store::SqliteStore, store::Store};
|
||||||
use atuin_common::record::{Host, HostId, Record};
|
use atuin_common::record::{Host, HostId, Record};
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
// do a sync :O
|
// do a sync :O
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
@ -76,30 +78,24 @@ pub async fn operations(
|
|||||||
for diff in diffs {
|
for diff in diffs {
|
||||||
let op = match (diff.local, diff.remote) {
|
let op = match (diff.local, diff.remote) {
|
||||||
// We both have it! Could be either. Compare.
|
// We both have it! Could be either. Compare.
|
||||||
(Some(local), Some(remote)) => {
|
(Some(local), Some(remote)) => match local.cmp(&remote) {
|
||||||
if local == remote {
|
Ordering::Equal => Operation::Noop {
|
||||||
// between the diff and now, a sync has somehow occured.
|
host: diff.host,
|
||||||
// regardless, no work is needed!
|
tag: diff.tag,
|
||||||
Operation::Noop {
|
},
|
||||||
host: diff.host,
|
Ordering::Greater => Operation::Upload {
|
||||||
tag: diff.tag,
|
local,
|
||||||
}
|
remote: Some(remote),
|
||||||
} else if local > remote {
|
host: diff.host,
|
||||||
Operation::Upload {
|
tag: diff.tag,
|
||||||
local,
|
},
|
||||||
remote: Some(remote),
|
Ordering::Less => Operation::Download {
|
||||||
host: diff.host,
|
local: Some(local),
|
||||||
tag: diff.tag,
|
remote,
|
||||||
}
|
host: diff.host,
|
||||||
} else {
|
tag: diff.tag,
|
||||||
Operation::Download {
|
},
|
||||||
local: Some(local),
|
},
|
||||||
remote,
|
|
||||||
host: diff.host,
|
|
||||||
tag: diff.tag,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remote has it, we don't. Gotta be download
|
// Remote has it, we don't. Gotta be download
|
||||||
(None, Some(remote)) => Operation::Download {
|
(None, Some(remote)) => Operation::Download {
|
||||||
@ -162,7 +158,7 @@ async fn sync_upload(
|
|||||||
println!(
|
println!(
|
||||||
"Uploading {} records to {}/{}",
|
"Uploading {} records to {}/{}",
|
||||||
expected,
|
expected,
|
||||||
host.0.as_simple().to_string(),
|
host.0.as_simple(),
|
||||||
tag
|
tag
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -173,7 +169,7 @@ async fn sync_upload(
|
|||||||
.await
|
.await
|
||||||
.map_err(|_| SyncError::LocalStoreError)?;
|
.map_err(|_| SyncError::LocalStoreError)?;
|
||||||
|
|
||||||
let _ = client
|
client
|
||||||
.post_records(&page)
|
.post_records(&page)
|
||||||
.await
|
.await
|
||||||
.map_err(|_| SyncError::RemoteRequestError)?;
|
.map_err(|_| SyncError::RemoteRequestError)?;
|
||||||
@ -206,7 +202,7 @@ async fn sync_download(
|
|||||||
println!(
|
println!(
|
||||||
"Downloading {} records from {}/{}",
|
"Downloading {} records from {}/{}",
|
||||||
expected,
|
expected,
|
||||||
host.0.as_simple().to_string(),
|
host.0.as_simple(),
|
||||||
tag
|
tag
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ use self::{
|
|||||||
models::{History, NewHistory, NewSession, NewUser, Session, User},
|
models::{History, NewHistory, NewSession, NewUser, Session, User},
|
||||||
};
|
};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use atuin_common::record::{EncryptedData, HostId, Record, RecordId, RecordIdx, RecordStatus};
|
use atuin_common::record::{EncryptedData, HostId, Record, RecordIdx, RecordStatus};
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
use time::{Date, Duration, Month, OffsetDateTime, Time, UtcOffset};
|
use time::{Date, Duration, Month, OffsetDateTime, Time, UtcOffset};
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use atuin_common::record::{EncryptedData, HostId, Record, RecordId, RecordIdx, RecordStatus};
|
use atuin_common::record::{EncryptedData, HostId, Record, RecordIdx, RecordStatus};
|
||||||
use atuin_server_database::models::{History, NewHistory, NewSession, NewUser, Session, User};
|
use atuin_server_database::models::{History, NewHistory, NewSession, NewUser, Session, User};
|
||||||
use atuin_server_database::{Database, DbError, DbResult};
|
use atuin_server_database::{Database, DbError, DbResult};
|
||||||
use futures_util::TryStreamExt;
|
use futures_util::TryStreamExt;
|
||||||
@ -398,8 +398,6 @@ impl Database for Postgres {
|
|||||||
count: u64,
|
count: u64,
|
||||||
) -> DbResult<Vec<Record<EncryptedData>>> {
|
) -> DbResult<Vec<Record<EncryptedData>>> {
|
||||||
tracing::debug!("{:?} - {:?} - {:?}", host, tag, start);
|
tracing::debug!("{:?} - {:?} - {:?}", host, tag, start);
|
||||||
let mut ret = Vec::with_capacity(count as usize);
|
|
||||||
let mut parent = start;
|
|
||||||
let start = start.unwrap_or(0);
|
let start = start.unwrap_or(0);
|
||||||
|
|
||||||
let records: Result<Vec<DbRecord>, DbError> = sqlx::query_as(
|
let records: Result<Vec<DbRecord>, DbError> = sqlx::query_as(
|
||||||
@ -433,8 +431,8 @@ impl Database for Postgres {
|
|||||||
records
|
records
|
||||||
}
|
}
|
||||||
Err(DbError::NotFound) => {
|
Err(DbError::NotFound) => {
|
||||||
tracing::debug!("hit end of store: {:?}/{}", host, tag);
|
tracing::debug!("no records found in store: {:?}/{}", host, tag);
|
||||||
return Ok(ret);
|
return Ok(vec![]);
|
||||||
}
|
}
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
};
|
};
|
||||||
|
@ -8,7 +8,7 @@ use super::{ErrorResponse, ErrorResponseStatus, RespExt};
|
|||||||
use crate::router::{AppState, UserAuth};
|
use crate::router::{AppState, UserAuth};
|
||||||
use atuin_server_database::Database;
|
use atuin_server_database::Database;
|
||||||
|
|
||||||
use atuin_common::record::{EncryptedData, HostId, Record, RecordId, RecordIdx, RecordStatus};
|
use atuin_common::record::{EncryptedData, HostId, Record, RecordIdx, RecordStatus};
|
||||||
|
|
||||||
#[instrument(skip_all, fields(user.id = user.id))]
|
#[instrument(skip_all, fields(user.id = user.id))]
|
||||||
pub async fn post<DB: Database>(
|
pub async fn post<DB: Database>(
|
||||||
|
@ -87,7 +87,7 @@ impl Cmd {
|
|||||||
|
|
||||||
Self::Kv(kv) => kv.run(&settings, &mut store).await,
|
Self::Kv(kv) => kv.run(&settings, &mut store).await,
|
||||||
|
|
||||||
Self::Record(record) => record.run(&settings, &mut store).await,
|
Self::Record(record) => record.run(&settings, &store).await,
|
||||||
|
|
||||||
Self::DefaultConfig => {
|
Self::DefaultConfig => {
|
||||||
config::run();
|
config::run();
|
||||||
|
@ -14,7 +14,7 @@ use atuin_client::{
|
|||||||
database::{current_context, Database},
|
database::{current_context, Database},
|
||||||
encryption,
|
encryption,
|
||||||
history::{store::HistoryStore, History},
|
history::{store::HistoryStore, History},
|
||||||
record::{sqlite_store::SqliteStore, store::Store},
|
record::sqlite_store::SqliteStore,
|
||||||
settings::Settings,
|
settings::Settings,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -12,10 +12,29 @@ pub enum Cmd {
|
|||||||
impl Cmd {
|
impl Cmd {
|
||||||
pub async fn run(
|
pub async fn run(
|
||||||
&self,
|
&self,
|
||||||
settings: &Settings,
|
_settings: &Settings,
|
||||||
store: &mut (impl Store + Send + Sync),
|
store: &(impl Store + Send + Sync),
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let host_id = Settings::host_id().expect("failed to get host_id");
|
let host_id = Settings::host_id().expect("failed to get host_id");
|
||||||
|
|
||||||
|
let status = store.status().await?;
|
||||||
|
|
||||||
|
for (host, store) in &status.hosts {
|
||||||
|
let host_string = if host == &host_id {
|
||||||
|
format!("host: {} <- CURRENT HOST", host.0.as_hyphenated())
|
||||||
|
} else {
|
||||||
|
format!("host: {}", host.0.as_hyphenated())
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("{host_string}");
|
||||||
|
|
||||||
|
for (tag, idx) in store {
|
||||||
|
println!("\tstore: {tag} at {idx}");
|
||||||
|
}
|
||||||
|
|
||||||
|
println!();
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ async fn run(
|
|||||||
db: &impl Database,
|
db: &impl Database,
|
||||||
store: &mut (impl Store + Send + Sync),
|
store: &mut (impl Store + Send + Sync),
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let (diff, remote_index) = sync::diff(settings, store).await?;
|
let (diff, _) = sync::diff(settings, store).await?;
|
||||||
let operations = sync::operations(diff, store).await?;
|
let operations = sync::operations(diff, store).await?;
|
||||||
let (uploaded, downloaded) = sync::sync_remote(operations, store, settings).await?;
|
let (uploaded, downloaded) = sync::sync_remote(operations, store, settings).await?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user