aboutsummaryrefslogtreecommitdiffstats
path: root/atuin-client/src/api_client.rs
diff options
context:
space:
mode:
Diffstat (limited to 'atuin-client/src/api_client.rs')
-rw-r--r--atuin-client/src/api_client.rs46
1 files changed, 27 insertions, 19 deletions
diff --git a/atuin-client/src/api_client.rs b/atuin-client/src/api_client.rs
index ae8df5ad..9007b9ab 100644
--- a/atuin-client/src/api_client.rs
+++ b/atuin-client/src/api_client.rs
@@ -13,11 +13,11 @@ use atuin_common::{
AddHistoryRequest, CountResponse, DeleteHistoryRequest, ErrorResponse, IndexResponse,
LoginRequest, LoginResponse, RegisterResponse, StatusResponse, SyncHistoryResponse,
},
- record::RecordIndex,
+ record::RecordStatus,
};
use atuin_common::{
api::{ATUIN_CARGO_VERSION, ATUIN_HEADER_VERSION, ATUIN_VERSION},
- record::{EncryptedData, HostId, Record, RecordId},
+ record::{EncryptedData, HostId, Record, RecordIdx},
};
use semver::Version;
use time::format_description::well_known::Rfc3339;
@@ -267,10 +267,18 @@ impl<'a> Client<'a> {
}
pub async fn post_records(&self, records: &[Record<EncryptedData>]) -> Result<()> {
- let url = format!("{}/record", self.sync_addr);
+ let url = format!("{}/api/v0/record", self.sync_addr);
let url = Url::parse(url.as_str())?;
- self.client.post(url).json(records).send().await?;
+ let resp = self.client.post(url).json(records).send().await?;
+ info!("posted records, got {}", resp.status());
+
+ if !resp.status().is_success() {
+ error!(
+ "failed to post records to server; got: {:?}",
+ resp.text().await
+ );
+ }
Ok(())
}
@@ -279,24 +287,22 @@ impl<'a> Client<'a> {
&self,
host: HostId,
tag: String,
- start: Option<RecordId>,
+ start: RecordIdx,
count: u64,
) -> Result<Vec<Record<EncryptedData>>> {
+ debug!(
+ "fetching record/s from host {}/{}/{}",
+ host.0.to_string(),
+ tag,
+ start
+ );
+
let url = format!(
- "{}/record/next?host={}&tag={}&count={}",
- self.sync_addr, host.0, tag, count
+ "{}/api/v0/record/next?host={}&tag={}&count={}&start={}",
+ self.sync_addr, host.0, tag, count, start
);
- let mut url = Url::parse(url.as_str())?;
- if let Some(start) = start {
- url.set_query(Some(
- format!(
- "host={}&tag={}&count={}&start={}",
- host.0, tag, count, start.0
- )
- .as_str(),
- ));
- }
+ let url = Url::parse(url.as_str())?;
let resp = self.client.get(url).send().await?;
@@ -305,8 +311,8 @@ impl<'a> Client<'a> {
Ok(records)
}
- pub async fn record_index(&self) -> Result<RecordIndex> {
- let url = format!("{}/record", self.sync_addr);
+ pub async fn record_status(&self) -> Result<RecordStatus> {
+ let url = format!("{}/api/v0/record", self.sync_addr);
let url = Url::parse(url.as_str())?;
let resp = self.client.get(url).send().await?;
@@ -317,6 +323,8 @@ impl<'a> Client<'a> {
let index = resp.json().await?;
+ debug!("got remote index {:?}", index);
+
Ok(index)
}