Skip to content

Commit

Permalink
Merge branch 'develop' into jm/metadata-sources
Browse files Browse the repository at this point in the history
  • Loading branch information
JMicheli committed Feb 4, 2025
2 parents de5784d + 899084d commit f550c9a
Show file tree
Hide file tree
Showing 32 changed files with 365 additions and 299 deletions.
3 changes: 3 additions & 0 deletions apps/server/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ impl From<prisma_client_rust::QueryError> for APIError {

/// The response body for API errors. This is just a basic JSON response with a status code and a message.
/// Any axum handlers which return a [`Result`] with an Error of [`APIError`] will be converted into this response.
#[derive(Debug)]
pub struct APIErrorResponse {
status: StatusCode,
message: String,
Expand All @@ -324,6 +325,8 @@ impl IntoResponse for APIErrorResponse {
"message": self.message,
});

tracing::error!(error = ?self, "API error response");

let base_response = Json(body).into_response();

let mut builder = Response::builder()
Expand Down
18 changes: 17 additions & 1 deletion apps/server/src/routers/koreader/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ use crate::{
middleware::auth::{api_key_middleware, RequestContext},
};

#[derive(Debug, Serialize, Deserialize)]
struct KOReaderURLParams<D> {
#[serde(flatten)]
params: D,
#[serde(default)]
api_key: Option<String>,
}

#[derive(Debug, Serialize, Deserialize)]
struct KOReaderDocumentURLParams {
document: String,
}

// TODO(koreader): healthcheck? I don't think it is required, since I could configure Stump as a
// sync server just fine without it.

Expand Down Expand Up @@ -98,7 +111,10 @@ struct GetProgressResponse {
async fn get_progress(
State(ctx): State<AppState>,
Extension(req): Extension<RequestContext>,
Path(document): Path<String>,
Path(KOReaderURLParams {
params: KOReaderDocumentURLParams { document },
..
}): Path<KOReaderURLParams<KOReaderDocumentURLParams>>,
) -> APIResult<Json<GetProgressResponse>> {
let client = &ctx.db;
let user = req.user();
Expand Down
58 changes: 39 additions & 19 deletions core/src/filesystem/scanner/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::{
filesystem::{MediaBuilder, SeriesBuilder},
job::{error::JobError, JobExecuteLog, JobProgress, WorkerCtx, WorkerSendExt},
prisma::{media, media_metadata, series, PrismaClient},
utils::chain_optional_iter,
CoreEvent,
};

Expand Down Expand Up @@ -162,30 +163,49 @@ pub(crate) async fn update_media(db: &PrismaClient, media: Media) -> CoreResult<
let result: Result<Media, QueryError> = db
._transaction()
.run(|client| async move {
if let Some(metadata) = media.metadata {
let params = metadata.into_prisma();
let updated_metadata = client
.media_metadata()
.update(media_metadata::media_id::equals(media.id.clone()), params)
.exec()
.await?;
tracing::trace!(?updated_metadata, "Metadata updated");
}
let metadata_id = match media.metadata {
Some(metadata) => {
let params = metadata
.into_prisma()
.into_iter()
.chain(vec![media_metadata::media_id::set(Some(
media.id.clone(),
))])
.collect::<Vec<_>>();
let updated_metadata = client
.media_metadata()
.upsert(
media_metadata::media_id::equals(media.id.clone()),
params.clone(),
params,
)
.exec()
.await?;
tracing::trace!(?updated_metadata, "Metadata upserted");
Some(updated_metadata.id)
},
_ => None,
};

let updated_media = client
.media()
.update(
media::id::equals(media.id.clone()),
vec![
media::name::set(media.name.clone()),
media::size::set(media.size),
media::extension::set(media.extension.clone()),
media::pages::set(media.pages),
media::hash::set(media.hash.clone()),
media::koreader_hash::set(media.koreader_hash.clone()),
media::path::set(media.path.clone()),
media::status::set(media.status.to_string()),
],
chain_optional_iter(
[
media::name::set(media.name.clone()),
media::size::set(media.size),
media::extension::set(media.extension.clone()),
media::pages::set(media.pages),
media::hash::set(media.hash.clone()),
media::koreader_hash::set(media.koreader_hash.clone()),
media::path::set(media.path.clone()),
media::status::set(media.status.to_string()),
],
[metadata_id.map(|id| {
media::metadata::connect(media_metadata::id::equals(id))
})],
),
)
.with(media::metadata::fetch())
.exec()
Expand Down
180 changes: 90 additions & 90 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
};

libraries = with pkgs;[
webkitgtk
webkitgtk_4_1
gtk3
cairo
gdk-pixbuf
glib
dbus
openssl_3
openssl
];

packages = with pkgs; [
# node
nodePackages.yarn
nodejs
(nodePackages.yarn.override {withNode = false;})
nodejs_20

# rust
rustfmt
Expand All @@ -42,11 +42,11 @@
wget
pkg-config
dbus
openssl_3
openssl
glib
gtk3
libsoup
webkitgtk
libsoup_2_4
webkitgtk_4_1

# avoid openssl linking error when local git version isn't compatible with openssl_3
git
Expand Down
3 changes: 2 additions & 1 deletion packages/i18n/src/locales/af.json
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,8 @@
"wait": "Once libraries are created, they'll be displayed here"
},
"links": {
"create": "Create library"
"create": "Create library",
"settings": "Go to settings"
}
},
"pagination": {
Expand Down
3 changes: 2 additions & 1 deletion packages/i18n/src/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,8 @@
"wait": "Once libraries are created, they'll be displayed here"
},
"links": {
"create": "Create library"
"create": "Create library",
"settings": "Go to settings"
}
},
"pagination": {
Expand Down
3 changes: 2 additions & 1 deletion packages/i18n/src/locales/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,8 @@
"wait": "Once libraries are created, they'll be displayed here"
},
"links": {
"create": "Create library"
"create": "Create library",
"settings": "Go to settings"
}
},
"pagination": {
Expand Down
Loading

0 comments on commit f550c9a

Please sign in to comment.