Skip to content

Commit

Permalink
feat: Development
Browse files Browse the repository at this point in the history
  • Loading branch information
ppodolsky committed Mar 4, 2024
1 parent 1d60c4b commit de0cae1
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 1 addition & 25 deletions bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use axum::body::Body;
use axum::extract::{Query, Request};
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use axum::routing::{delete, head, post, put};
use axum::routing::{delete, get, post, put};
use axum::{
extract::{Path, State},
routing::get,
Json, Router,
};
use clap::{Parser, Subcommand};
Expand Down Expand Up @@ -97,12 +96,6 @@ struct AppState {
config: Arc<RwLock<Config>>,
config_path: PathBuf,
}

#[derive(Serialize)]
struct TableExistsResponse {
pub exists: bool,
}

#[derive(Serialize)]
struct TablesExistsResponse {
pub exists: bool,
Expand Down Expand Up @@ -160,7 +153,6 @@ async fn app() -> Result<(), Error> {
.route("/tables/:table/", get(table_ls))
.route("/tables/:table/share/", get(table_share))
.route("/tables/:table/*key", get(table_get))
.route("/tables/:table/*key", head(table_exists))
.route("/tables/:table/*key", put(table_insert))
.route("/tables/:table/*key", delete(table_delete))
.route("/tables/foreign_insert/", post(table_foreign_insert))
Expand Down Expand Up @@ -466,22 +458,6 @@ async fn table_delete(
}
}

async fn table_exists(
State(state): State<AppState>,
Path((table, key)): Path<(String, String)>,
) -> Response {
match state
.iroh_node
.read()
.await
.table_exists(&table, &key)
.await
{
Ok(exists) => Json(TableExistsResponse { exists }).into_response(),
Err(e) => e.into_response(),
}
}

async fn table_ls(State(state): State<AppState>, Path(table): Path<String>) -> Response {
match state.iroh_node.read().await.table_keys(&table) {
Some(stream) => Response::builder().body(Body::from_stream(stream)).unwrap(),
Expand Down
7 changes: 0 additions & 7 deletions src/iroh_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,6 @@ impl IrohNode {
}
}

pub async fn table_exists(&self, table_name: &str, key: &str) -> Result<bool> {
match self.table_storages.get(table_name) {
Some(table_storage) => Ok(table_storage.exists(key).await?.is_some()),
None => Err(Error::missing_table(table_name)),
}
}

pub fn table_keys(&self, table_name: &str) -> Option<impl Stream<Item = Result<String>>> {
self.table_storages.get(table_name).cloned().map_or_else(
|| None,
Expand Down
15 changes: 0 additions & 15 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,21 +351,6 @@ impl Storage {
})
}

pub async fn exists(&self, key: &str) -> Result<Option<PathBuf>> {
for file_shard_config in self.hash_ring.range(key, 1) {
let file_shard = &self.shards[&file_shard_config.name];
if file_shard
.exists(key)
.await
.map_err(Error::io_error)?
.is_some()
{
return Ok(Some(file_shard.get_path_for(key)));
}
}
Ok(None)
}

pub fn iroh_doc(&self) -> &IrohDoc {
&self.iroh_doc
}
Expand Down
2 changes: 1 addition & 1 deletion trident-py/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "izihawa-trident-client"
version = "1.1.0"
version = "1.1.1"
description = ""
authors = ["Pasha Podolsky <[email protected]>"]
readme = "README.md"
Expand Down
5 changes: 1 addition & 4 deletions trident-py/trident/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,4 @@ async def table_ls(self, table) -> typing.AsyncGenerator[str, None]:
async def table_exists(self, table: str, key: str) -> bool:
url = f"/tables/{table}/{key}"
response = await self.head(url)
if response is None:
return False
response = await response.json()
return response["exists"]
return response is not None

0 comments on commit de0cae1

Please sign in to comment.