diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2023-07-14 20:44:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-14 20:44:08 +0100 |
| commit | 97e24d0d41bb743833e457de5ba49c5c233eb3b3 (patch) | |
| tree | f0cfefd9048df83d3029cb0b0d21f1f88813fe2e /atuin-client/src/api_client.rs | |
| parent | Bump semver from 5.7.1 to 5.7.2 in /docs (#1100) (diff) | |
| download | atuin-97e24d0d41bb743833e457de5ba49c5c233eb3b3.zip | |
Add new sync (#1093)
* Add record migration
* Add database functions for inserting history
No real tests yet :( I would like to avoid running postgres lol
* Add index handler, use UUIDs not strings
* Fix a bunch of tests, remove Option<Uuid>
* Add tests, all passing
* Working upload sync
* Record downloading works
* Sync download works
* Don't waste requests
* Use a page size for uploads, make it variable later
* Aaaaaand they're encrypted now too
* Add cek
* Allow reading tail across hosts
* Revert "Allow reading tail across hosts"
Not like that
This reverts commit 7b0c72e7e050c358172f9b53cbd21b9e44cf4931.
* Handle multiple shards properly
* format
* Format and make clippy happy
* use some fancy types (#1098)
* use some fancy types
* fmt
* Goodbye horrible tuple
* Update atuin-server-postgres/migrations/20230623070418_records.sql
Co-authored-by: Conrad Ludgate <conradludgate@gmail.com>
* fmt
* Sort tests too because time sucks
* fix features
---------
Co-authored-by: Conrad Ludgate <conradludgate@gmail.com>
Diffstat (limited to 'atuin-client/src/api_client.rs')
| -rw-r--r-- | atuin-client/src/api_client.rs | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/atuin-client/src/api_client.rs b/atuin-client/src/api_client.rs index 350c419d..5ae1ed0a 100644 --- a/atuin-client/src/api_client.rs +++ b/atuin-client/src/api_client.rs @@ -8,9 +8,13 @@ use reqwest::{ StatusCode, Url, }; -use atuin_common::api::{ - AddHistoryRequest, CountResponse, DeleteHistoryRequest, ErrorResponse, IndexResponse, - LoginRequest, LoginResponse, RegisterResponse, StatusResponse, SyncHistoryResponse, +use atuin_common::record::{EncryptedData, HostId, Record, RecordId}; +use atuin_common::{ + api::{ + AddHistoryRequest, CountResponse, DeleteHistoryRequest, ErrorResponse, IndexResponse, + LoginRequest, LoginResponse, RegisterResponse, StatusResponse, SyncHistoryResponse, + }, + record::RecordIndex, }; use semver::Version; @@ -195,6 +199,55 @@ impl<'a> Client<'a> { Ok(()) } + pub async fn post_records(&self, records: &[Record<EncryptedData>]) -> Result<()> { + let url = format!("{}/record", self.sync_addr); + let url = Url::parse(url.as_str())?; + + self.client.post(url).json(records).send().await?; + + Ok(()) + } + + pub async fn next_records( + &self, + host: HostId, + tag: String, + start: Option<RecordId>, + count: u64, + ) -> Result<Vec<Record<EncryptedData>>> { + let url = format!( + "{}/record/next?host={}&tag={}&count={}", + self.sync_addr, host.0, tag, count + ); + 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 resp = self.client.get(url).send().await?; + + let records = resp.json::<Vec<Record<EncryptedData>>>().await?; + + Ok(records) + } + + pub async fn record_index(&self) -> Result<RecordIndex> { + let url = format!("{}/record", self.sync_addr); + let url = Url::parse(url.as_str())?; + + let resp = self.client.get(url).send().await?; + let index = resp.json().await?; + + Ok(index) + } + pub async fn delete(&self) -> Result<()> { let url = format!("{}/account", self.sync_addr); let url = Url::parse(url.as_str())?; |
