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