-
Notifications
You must be signed in to change notification settings - Fork 1
Wp/ updated delete file to use pk as filename #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
25eef4c
61b2edc
eddf0d5
07e5283
227ed37
7d85f6b
e148dd9
8f30773
767156c
f02bc40
ab317e4
908e39d
5f6c4c2
ba92b5d
684bb7c
fc8634e
29a31b4
e50a2d5
6b77b22
657c120
50dc264
dedb85d
13134f7
2f2e403
cbf7e9b
990420d
eff5232
d32eeca
5b9a950
91ae1b9
30f7878
a7fc00a
01ba0f7
8e88ead
9e3a446
8849101
ea0c994
4629aa2
3e9949d
d1f9216
961f663
730f208
7188500
7db7d4d
4e21025
642acb4
8637f02
04d53bf
04ef77f
dd5fa8c
c675bd0
18fc5df
f651742
c4329ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
pub mod fs; | ||
// pub mod task; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ use std::{net::SocketAddr, str::FromStr}; | |
use anyhow::Result; | ||
use axum::{ | ||
body::StreamBody, | ||
extract::{BodyStream, Path}, | ||
extract::{BodyStream, Path, Query}, | ||
http::StatusCode, | ||
response::{IntoResponse, Response}, | ||
routing::{delete, get, post}, | ||
|
@@ -16,11 +16,33 @@ use secp256k1::PublicKey; | |
use tower_http::cors::CorsLayer; | ||
|
||
use crate::{ | ||
backend::fs::{delete_file, read_file, write_file, FileStream}, | ||
backend::fs::{delete_file, read_file, read_slice, write_file, FileStream}, | ||
config::{node_shared_secret, SYS_CFG}, | ||
prelude::*, | ||
}; | ||
|
||
struct FileSlice { | ||
//#[serde(default, deserialize_with = "empty_string_as_none")] | ||
pk: String, | ||
black3_hash: String, | ||
index_start: usize, | ||
range_end: usize, | ||
} | ||
|
||
/// Serde deserialization decorator to map empty Strings to None, | ||
// fn empty_string_as_none<'de, D, T>(de: D) -> Result<Option<T>, D::Error> | ||
// where | ||
// D: Deserializer<'de>, | ||
// T: FromStr, | ||
// T::Err: fmt::Display, | ||
// { | ||
// let opt = Option::<String>::deserialize(de)?; | ||
// match opt.as_deref() { | ||
// None | Some("") => Ok(None), | ||
// Some(s) => FromStr::from_str(s).map_err(de::Error::custom).map(Some), | ||
// } | ||
// } | ||
|
||
#[axum_macros::debug_handler] | ||
async fn post_file( | ||
Path(pk): Path<String>, | ||
|
@@ -69,13 +91,32 @@ async fn get_file( | |
Ok((StatusCode::OK, StreamBody::new(file_stream))) | ||
} | ||
|
||
// #[axum_macros::debug_handler] | ||
// //async fn get_slice(Query(my_params): Query<FileSlice>) -> Result<impl IntoResponse, AppError> { | ||
// async fn get_slice(Query(my_params): Query<FileSlice>) -> Result<impl IntoResponse, AppError> { | ||
// // let pk = my_params.black3_hash; | ||
// // let blake3_hash = my_params.black3_hash; | ||
// // let start_index = my_params.index_start; | ||
// // let range_end = my_params.range_end; | ||
// // debug!("my_params :: blake {:?} ", my_params.black3_hash); | ||
// // debug!("my_params :: start {:?} ", my_params.index_start); | ||
// // debug!("my_params :: end {:?} ", my_params.range_end); | ||
// let file_stream = read_slices( | ||
// my_params.pk, | ||
// my_params.black3_hash, | ||
// my_params.index_start, | ||
// my_params.range_end, | ||
// ) | ||
// .await?; | ||
// Ok((StatusCode::OK, StreamBody::new(file_stream))) | ||
// } | ||
|
||
#[axum_macros::debug_handler] | ||
async fn remove_file( | ||
Path((pk, blake3_hash)): Path<(String, String)>, | ||
) -> Result<impl IntoResponse, AppError> { | ||
async fn remove_file(Path(pk): Path<String>) -> Result<impl IntoResponse, AppError> { | ||
let pk = Secp256k1PubKey::try_from(pk.as_str())?; | ||
delete_file(pk, blake3_hash.as_bytes())?; | ||
Ok((StatusCode::OK, blake3_hash)) | ||
let del = delete_file(&pk).await.is_ok(); | ||
|
||
Ok((StatusCode::OK, del.to_string())) | ||
} | ||
|
||
async fn key(Path(pk): Path<String>) -> Result<impl IntoResponse, AppError> { | ||
|
@@ -89,9 +130,10 @@ async fn key(Path(pk): Path<String>) -> Result<impl IntoResponse, AppError> { | |
|
||
pub async fn start() -> Result<()> { | ||
let app = Router::new() | ||
.route("/remove/:pk/:blake3_hash", delete(remove_file)) | ||
.route("/remove/:blake3_hash", delete(remove_file)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You removed the pk... We'll need this to be passed for the changes I'm making in #39. I've trimmed that PR down so we can get that merged and you can use that to make sure file deletion is namespaced by pk. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, your changes address that. |
||
.route("/store/:pk", post(post_file)) | ||
.route("/retrieve/:pk/:blake3_hash", get(get_file)) | ||
// .route("/slice/", get(get_slice)) | ||
.route("/key/:pk", get(key)) | ||
// .route("/catalog/:blake3_hash", get(get_catalog)) | ||
// .route("/raw/:bao_hash", get(get_raw)) | ||
|
Uh oh!
There was an error while loading. Please reload this page.