feat(database): remove unused SQL queries and update Cargo dependencies

This commit is contained in:
2026-05-04 14:00:33 +02:00
parent d769a5b55c
commit fa8efbaa23
22 changed files with 89 additions and 687 deletions

View File

@@ -9,6 +9,7 @@ anyhow = { workspace = true }
async-trait = { workspace = true }
tracing = { workspace = true }
object_store = { workspace = true }
infer = "0.19.0"
[dev-dependencies]
tokio = { workspace = true }

View File

@@ -7,9 +7,15 @@ use domain::{
ports::PosterStorage,
value_objects::{MovieId, PosterPath},
};
use object_store::{path::Path, ObjectStore};
use object_store::{Attribute, Attributes, PutOptions, path::Path, ObjectStore};
use std::sync::Arc;
fn detect_mime(bytes: &[u8]) -> &'static str {
infer::get(bytes)
.map(|t| t.mime_type())
.unwrap_or("application/octet-stream")
}
pub struct PosterStorageAdapter {
store: Arc<dyn ObjectStore>,
}
@@ -32,8 +38,12 @@ impl PosterStorage for PosterStorageAdapter {
image_bytes: &[u8],
) -> Result<PosterPath, DomainError> {
let path = Path::from(movie_id.value().to_string());
let mime = detect_mime(image_bytes);
let mut attributes = Attributes::new();
attributes.insert(Attribute::ContentType, mime.into());
let opts = PutOptions { attributes, ..Default::default() };
self.store
.put(&path, image_bytes.to_vec().into())
.put_opts(&path, image_bytes.to_vec().into(), opts)
.await
.map_err(|e| DomainError::InfrastructureError(e.to_string()))?;
PosterPath::new(path.to_string())

View File

@@ -5,7 +5,7 @@
<article class="entry">
{% if let Some(poster) = entry.movie().poster_path() %}
<div class="poster">
<img src="/static/posters/{{ poster.value() }}" alt="">
<img src="/posters/{{ poster.value() }}" alt="">
</div>
{% endif %}
<div class="entry-body">

View File

@@ -30,6 +30,7 @@ sqlx = { workspace = true }
template-askama = { workspace = true }
event-publisher = { workspace = true }
rss = { workspace = true }
infer = "0.19.0"
[dev-dependencies]
tower = { version = "0.5", features = ["util"] }

View File

@@ -1,6 +1,19 @@
use serde::{Deserialize, Serialize};
use uuid::Uuid;
fn empty_string_as_none<'de, D, T>(de: D) -> Result<Option<T>, D::Error>
where
D: serde::Deserializer<'de>,
T: std::str::FromStr,
T::Err: std::fmt::Display,
{
let s = Option::<String>::deserialize(de)?;
match s.as_deref() {
None | Some("") => Ok(None),
Some(s) => s.parse::<T>().map(Some).map_err(serde::de::Error::custom),
}
}
#[derive(Deserialize)]
pub struct DiaryQueryParams {
pub limit: Option<u32>,
@@ -11,11 +24,16 @@ pub struct DiaryQueryParams {
#[derive(Deserialize)]
pub struct LogReviewForm {
#[serde(default, deserialize_with = "empty_string_as_none")]
pub external_metadata_id: Option<String>,
#[serde(default, deserialize_with = "empty_string_as_none")]
pub manual_title: Option<String>,
#[serde(default, deserialize_with = "empty_string_as_none")]
pub manual_release_year: Option<u16>,
#[serde(default, deserialize_with = "empty_string_as_none")]
pub manual_director: Option<String>,
pub rating: u8,
#[serde(default, deserialize_with = "empty_string_as_none")]
pub comment: Option<String>,
pub watched_at: String,
}

View File

@@ -218,7 +218,7 @@ pub mod html {
};
let cmd = LogReviewCommand {
external_metadata_id: form.external_metadata_id,
external_metadata_id: form.external_metadata_id.filter(|s| !s.trim().is_empty()),
manual_title: form.manual_title,
manual_release_year: form.manual_release_year,
manual_director: form.manual_director,
@@ -238,6 +238,37 @@ pub mod html {
}
}
pub mod posters {
use axum::{
extract::{Path, State},
http::{StatusCode, header},
response::IntoResponse,
};
use domain::value_objects::PosterPath;
use crate::state::AppState;
pub async fn get_poster(
State(state): State<AppState>,
Path(path): Path<String>,
) -> impl IntoResponse {
let poster_path = match PosterPath::new(path) {
Ok(p) => p,
Err(_) => return StatusCode::BAD_REQUEST.into_response(),
};
match state.app_ctx.poster_storage.get_poster(&poster_path).await {
Ok(bytes) => {
let mime = infer::get(&bytes)
.map(|t| t.mime_type())
.unwrap_or("application/octet-stream");
([(header::CONTENT_TYPE, mime)], bytes).into_response()
}
Err(_) => StatusCode::NOT_FOUND.into_response(),
}
}
}
pub mod rss {
use axum::{
extract::State,
@@ -360,7 +391,7 @@ pub mod api {
})?;
let cmd = LogReviewCommand {
external_metadata_id: req.external_metadata_id,
external_metadata_id: req.external_metadata_id.filter(|s| !s.trim().is_empty()),
manual_title: req.manual_title,
manual_release_year: req.manual_release_year,
manual_director: req.manual_director,

View File

@@ -28,6 +28,7 @@ fn html_routes() -> Router<AppState> {
)
.route("/reviews/new", routing::get(handlers::html::get_new_review_page))
.route("/reviews", routing::post(handlers::html::post_review))
.route("/posters/{path}", routing::get(handlers::posters::get_poster))
.route("/feed.rss", routing::get(handlers::rss::get_feed))
}