1
Fork 0
mirror of https://github.com/thegeneralist01/archivr synced 2026-07-21 18:55:36 +02:00

feat(server): add GET /entries/:uid/favicon endpoint

This commit is contained in:
TheGeneralist 2026-06-24 19:16:21 +02:00
parent cc2dbf4ac2
commit 1206d7103d
Signed by: thegeneralist01
SSH key fingerprint: SHA256:pp9qddbCNmVNoSjevdvQvM5z0DHN7LTa8qBMbcMq/R4

View file

@ -67,6 +67,10 @@ pub fn app(registry: ServerRegistry) -> Router {
"/api/archives/:archive_id/entries/:entry_uid/artifacts/:artifact_index", "/api/archives/:archive_id/entries/:entry_uid/artifacts/:artifact_index",
get(serve_artifact), get(serve_artifact),
) )
.route(
"/api/archives/:archive_id/entries/:entry_uid/favicon",
get(serve_entry_favicon),
)
.route("/api/archives/:archive_id/runs", get(list_runs)) .route("/api/archives/:archive_id/runs", get(list_runs))
.route("/api/archives/:archive_id/captures", post(capture_handler)) .route("/api/archives/:archive_id/captures", post(capture_handler))
.route("/api/archives/:archive_id/tags", get(list_tags).post(create_tag_handler)) .route("/api/archives/:archive_id/tags", get(list_tags).post(create_tag_handler))
@ -162,6 +166,29 @@ async fn serve_artifact(
.into_response()) .into_response())
} }
async fn serve_entry_favicon(
State(state): State<AppState>,
Path((archive_id, entry_uid)): Path<(String, String)>,
req: Request,
) -> Result<Response, ApiError> {
let mounted = mounted_archive(&state, &archive_id)?;
let paths = archive::read_archive_paths(&mounted.archive_path)?;
let conn = database::open_or_initialize(&mounted.archive_path)?;
let detail = archive::get_entry_detail(&conn, &entry_uid)?
.ok_or(ApiError::not_found("entry not found"))?;
let artifact = detail
.artifacts
.iter()
.find(|a| a.artifact_role == "favicon")
.ok_or(ApiError::not_found("no favicon for this entry"))?;
let file_path = archive::resolve_artifact_path(&paths.store_path, artifact)?;
Ok(ServeFile::new(&file_path)
.oneshot(req)
.await
.unwrap()
.into_response())
}
#[derive(Debug, serde::Deserialize)] #[derive(Debug, serde::Deserialize)]
struct CreateTagBody { struct CreateTagBody {
path: String, path: String,