add DELETE endpoint for objects, update URLs (/get/ -> /obj/)
This commit is contained in:
parent
9ae09cc72f
commit
7fd537a948
2 changed files with 20 additions and 4 deletions
|
@ -1,10 +1,10 @@
|
|||
use crate::addressing::Address;
|
||||
use crate::database::{retrieve_file, retrieve_object, DbPool, Entry};
|
||||
use crate::database::{remove_object, retrieve_file, retrieve_object, DbPool, Entry};
|
||||
use crate::filesystem::{list_directory, lookup_by_filename, UPath};
|
||||
use crate::hash::{decode, encode};
|
||||
use actix_files::NamedFile;
|
||||
use actix_web::error::{ErrorBadRequest, ErrorInternalServerError, ErrorNotFound};
|
||||
use actix_web::{error, get, post, web, Error, HttpResponse};
|
||||
use actix_web::{delete, error, get, post, web, Error, HttpResponse};
|
||||
use anyhow::Result;
|
||||
use log::debug;
|
||||
use serde::Deserialize;
|
||||
|
@ -39,7 +39,7 @@ pub async fn get_raw(state: web::Data<State>, hash: web::Path<String>) -> Result
|
|||
}
|
||||
}
|
||||
|
||||
#[get("/api/get/{address_str}")]
|
||||
#[get("/api/obj/{address_str}")]
|
||||
pub async fn get_object(
|
||||
state: web::Data<State>,
|
||||
address_str: web::Path<String>,
|
||||
|
@ -60,6 +60,22 @@ pub async fn get_object(
|
|||
Ok(HttpResponse::Ok().json(result))
|
||||
}
|
||||
|
||||
#[delete("/api/obj/{address_str}")]
|
||||
pub async fn delete_object(
|
||||
state: web::Data<State>,
|
||||
address_str: web::Path<String>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let connection = state.db_pool.get().map_err(ErrorInternalServerError)?;
|
||||
let _ = remove_object(
|
||||
&connection,
|
||||
Address::decode(&decode(address_str.into_inner()).map_err(ErrorBadRequest)?)
|
||||
.map_err(ErrorInternalServerError)?,
|
||||
)
|
||||
.map_err(ErrorInternalServerError)?;
|
||||
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
#[get("/api/hier/{path:.*}")]
|
||||
pub async fn list_hier(
|
||||
state: web::Data<State>,
|
||||
|
|
|
@ -84,7 +84,7 @@ export default defineComponent({
|
|||
}
|
||||
},
|
||||
setup(props) {
|
||||
const {data, error} = useSWRV<ListingResult, unknown>(() => `/api/get/${props.address}`, fetcher);
|
||||
const {data, error} = useSWRV<ListingResult, unknown>(() => `/api/obj/${props.address}`, fetcher);
|
||||
|
||||
return {
|
||||
data,
|
||||
|
|
Loading…
Reference in a new issue