mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-12-22 19:31:35 +00:00
Add admin endpoint to fetch identifier from an alias
This commit is contained in:
parent
17dab63662
commit
9db057fdc5
5 changed files with 32 additions and 1 deletions
19
src/main.rs
19
src/main.rs
|
@ -954,6 +954,19 @@ async fn aliases<R: FullRepo>(
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn identifier<R: FullRepo, S: Store>(
|
||||||
|
query: web::Query<AliasQuery>,
|
||||||
|
repo: web::Data<R>,
|
||||||
|
) -> Result<HttpResponse, Error> {
|
||||||
|
let alias = query.into_inner().alias;
|
||||||
|
let identifier = repo.identifier_from_alias::<S::Identifier>(&alias).await?;
|
||||||
|
|
||||||
|
Ok(HttpResponse::Ok().json(&serde_json::json!({
|
||||||
|
"msg": "ok",
|
||||||
|
"identifier": identifier.string_repr(),
|
||||||
|
})))
|
||||||
|
}
|
||||||
|
|
||||||
fn transform_error(error: actix_form_data::Error) -> actix_web::Error {
|
fn transform_error(error: actix_form_data::Error) -> actix_web::Error {
|
||||||
let error: Error = error.into();
|
let error: Error = error.into();
|
||||||
let error: actix_web::Error = error.into();
|
let error: actix_web::Error = error.into();
|
||||||
|
@ -1070,7 +1083,11 @@ async fn launch<R: FullRepo + 'static, SC: StoreConfig + 'static>(
|
||||||
web::resource("/variants").route(web::delete().to(clean_variants::<R>)),
|
web::resource("/variants").route(web::delete().to(clean_variants::<R>)),
|
||||||
)
|
)
|
||||||
.service(web::resource("/purge").route(web::post().to(purge::<R>)))
|
.service(web::resource("/purge").route(web::post().to(purge::<R>)))
|
||||||
.service(web::resource("/aliases").route(web::get().to(aliases::<R>))),
|
.service(web::resource("/aliases").route(web::get().to(aliases::<R>)))
|
||||||
|
.service(
|
||||||
|
web::resource("/identifier")
|
||||||
|
.route(web::get().to(identifier::<R, SC::Store>)),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.bind(CONFIG.server.address)?
|
.bind(CONFIG.server.address)?
|
||||||
|
|
|
@ -850,6 +850,10 @@ impl Identifier for Vec<u8> {
|
||||||
fn to_bytes(&self) -> Result<Vec<u8>, Error> {
|
fn to_bytes(&self) -> Result<Vec<u8>, Error> {
|
||||||
Ok(self.clone())
|
Ok(self.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn string_repr(&self) -> String {
|
||||||
|
base64::encode(self.as_slice())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -13,6 +13,8 @@ pub(crate) trait Identifier: Send + Sync + Clone + Debug {
|
||||||
fn from_bytes(bytes: Vec<u8>) -> Result<Self, Error>
|
fn from_bytes(bytes: Vec<u8>) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
|
|
||||||
|
fn string_repr(&self) -> String;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait StoreConfig: Send + Sync + Clone {
|
pub(crate) trait StoreConfig: Send + Sync + Clone {
|
||||||
|
|
|
@ -32,6 +32,10 @@ impl Identifier for FileId {
|
||||||
|
|
||||||
Ok(id)
|
Ok(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn string_repr(&self) -> String {
|
||||||
|
self.0.to_string_lossy().into_owned()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileId {
|
impl FileId {
|
||||||
|
|
|
@ -16,6 +16,10 @@ impl Identifier for ObjectId {
|
||||||
String::from_utf8(bytes).map_err(ObjectError::from)?,
|
String::from_utf8(bytes).map_err(ObjectError::from)?,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn string_repr(&self) -> String {
|
||||||
|
self.0.clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectId {
|
impl ObjectId {
|
||||||
|
|
Loading…
Reference in a new issue