| 1 | //! Authenticated projection of the existing Native avatar registrations. |
| 2 | use super::RuntimeApiState; |
| 3 | use axum::{Json, extract::State}; |
| 4 | |
| 5 | pub(super) async fn list_avatars( |
| 6 | State(state): State<RuntimeApiState>, |
| 7 | ) -> Json<Vec<codewhale_protocol::avatar::RegisteredPack>> { |
| 8 | Json(codewhale_engine::extension_host::avatars::catalog(state.workspace.clone()).await) |
| 9 | } |
| 10 | |
| 11 | #[derive(serde::Deserialize)] |
| 12 | #[serde(rename_all = "camelCase")] |
| 13 | pub(super) struct AtlasQuery { |
| 14 | content_hash: String, |
| 15 | } |
| 16 | |
| 17 | pub(super) async fn get_atlas( |
| 18 | State(state): State<RuntimeApiState>, |
| 19 | axum::extract::Path((handle, page)): axum::extract::Path<(u64, usize)>, |
| 20 | axum::extract::Query(query): axum::extract::Query<AtlasQuery>, |
| 21 | ) -> Result<Json<String>, axum::http::StatusCode> { |
| 22 | codewhale_engine::extension_host::avatars::atlas( |
| 23 | state.workspace.clone(), |
| 24 | handle, |
| 25 | page, |
| 26 | &query.content_hash, |
| 27 | ) |
| 28 | .await |
| 29 | .map(Json) |
| 30 | .ok_or(axum::http::StatusCode::NOT_FOUND) |
| 31 | } |
| 32 |