diff --git a/src/main.rs b/src/main.rs index 2d83b9f..c875a43 100644 --- a/src/main.rs +++ b/src/main.rs @@ -954,6 +954,19 @@ async fn aliases( }))) } +async fn identifier( + query: web::Query, + repo: web::Data, +) -> Result { + let alias = query.into_inner().alias; + let identifier = repo.identifier_from_alias::(&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 { let error: Error = error.into(); let error: actix_web::Error = error.into(); @@ -1070,7 +1083,11 @@ async fn launch( web::resource("/variants").route(web::delete().to(clean_variants::)), ) .service(web::resource("/purge").route(web::post().to(purge::))) - .service(web::resource("/aliases").route(web::get().to(aliases::))), + .service(web::resource("/aliases").route(web::get().to(aliases::))) + .service( + web::resource("/identifier") + .route(web::get().to(identifier::)), + ), ) }) .bind(CONFIG.server.address)? diff --git a/src/repo.rs b/src/repo.rs index 3ecc70d..aa75244 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -850,6 +850,10 @@ impl Identifier for Vec { fn to_bytes(&self) -> Result, Error> { Ok(self.clone()) } + + fn string_repr(&self) -> String { + base64::encode(self.as_slice()) + } } #[cfg(test)] diff --git a/src/store.rs b/src/store.rs index def70ce..98b22b0 100644 --- a/src/store.rs +++ b/src/store.rs @@ -13,6 +13,8 @@ pub(crate) trait Identifier: Send + Sync + Clone + Debug { fn from_bytes(bytes: Vec) -> Result where Self: Sized; + + fn string_repr(&self) -> String; } pub(crate) trait StoreConfig: Send + Sync + Clone { diff --git a/src/store/file_store/file_id.rs b/src/store/file_store/file_id.rs index cb6ea4e..dab2eb2 100644 --- a/src/store/file_store/file_id.rs +++ b/src/store/file_store/file_id.rs @@ -32,6 +32,10 @@ impl Identifier for FileId { Ok(id) } + + fn string_repr(&self) -> String { + self.0.to_string_lossy().into_owned() + } } impl FileId { diff --git a/src/store/object_store/object_id.rs b/src/store/object_store/object_id.rs index d9c8a4e..129d41b 100644 --- a/src/store/object_store/object_id.rs +++ b/src/store/object_store/object_id.rs @@ -16,6 +16,10 @@ impl Identifier for ObjectId { String::from_utf8(bytes).map_err(ObjectError::from)?, )) } + + fn string_repr(&self) -> String { + self.0.clone() + } } impl ObjectId {