Skip to content

Commit 6676d34

Browse files
authored
🔀 Promote experimental features (#560)
2 parents 2cf45b4 + e7cde28 commit 6676d34

File tree

71 files changed

+1202
-221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1202
-221
lines changed

Cargo.lock

+6-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/server/src/main.rs

-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ fn debug_setup() {
1818
"STUMP_CLIENT_DIR",
1919
env!("CARGO_MANIFEST_DIR").to_string() + "/../web/dist",
2020
);
21-
std::env::set_var(
22-
"EMAIL_TEMPLATES_DIR",
23-
env!("CARGO_MANIFEST_DIR").to_string() + "/../../crates/email/templates",
24-
);
2521
std::env::set_var("STUMP_PROFILE", "debug");
2622
}
2723

apps/server/src/routers/api/v1/media/individual.rs

+116-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ use specta::Type;
1111
use stump_core::{
1212
db::entity::{
1313
macros::{
14-
finished_reading_session_with_book_pages, reading_session_with_book_pages,
14+
finished_reading_session_with_book_pages, media_id_select,
15+
reading_session_with_book_pages,
1516
},
16-
ActiveReadingSession, FinishedReadingSession, Media, PageDimension,
17-
PageDimensionsEntity, ProgressUpdateReturn, User, UserPermission,
17+
ActiveReadingSession, FinishedReadingSession, Media, MediaMetadata,
18+
PageDimension, PageDimensionsEntity, ProgressUpdateReturn, User, UserPermission,
1819
},
1920
filesystem::{analyze_media_job::AnalyzeMediaJob, get_page_async},
2021
prisma::{
@@ -807,3 +808,115 @@ async fn fetch_media_page_dimensions_with_permissions(
807808

808809
Ok(dimensions_entity)
809810
}
811+
812+
#[utoipa::path(
813+
get,
814+
path = "/api/v1/media/:id/metadata",
815+
tag = "media",
816+
params(
817+
("id" = String, Path, description = "The ID of the media to get metadata for")
818+
),
819+
responses(
820+
(status = 200, description = "Successfully fetched media metadata"),
821+
(status = 401, description = "Unauthorized"),
822+
(status = 403, description = "Forbidden"),
823+
(status = 404, description = "Media metadata not available"),
824+
(status = 500, description = "Internal server error"),
825+
)
826+
)]
827+
/// Get the metadata for a media record
828+
pub(crate) async fn get_media_metadata(
829+
Path(id): Path<String>,
830+
State(ctx): State<AppState>,
831+
Extension(req): Extension<RequestContext>,
832+
) -> APIResult<Json<Option<MediaMetadata>>> {
833+
let db = &ctx.db;
834+
let user = req.user();
835+
let age_restrictions = user
836+
.age_restriction
837+
.as_ref()
838+
.map(|ar| apply_media_age_restriction(ar.age, ar.restrict_on_unset));
839+
let where_params = chain_optional_iter(
840+
[media::id::equals(id.clone())]
841+
.into_iter()
842+
.chain(apply_media_library_not_hidden_for_user_filter(user))
843+
.collect::<Vec<WhereParam>>(),
844+
[age_restrictions],
845+
);
846+
847+
let meta = db
848+
.media_metadata()
849+
.find_first(vec![media_metadata::media::is(where_params)])
850+
.exec()
851+
.await?;
852+
853+
Ok(Json(meta.map(MediaMetadata::from)))
854+
}
855+
856+
#[utoipa::path(
857+
put,
858+
path = "/api/v1/media/:id/metadata",
859+
tag = "media",
860+
params(
861+
("id" = String, Path, description = "The ID of the media to update metadata for")
862+
),
863+
responses(
864+
(status = 200, description = "Successfully updated media metadata"),
865+
(status = 401, description = "Unauthorized"),
866+
(status = 403, description = "Forbidden"),
867+
(status = 404, description = "Media metadata not available"),
868+
(status = 500, description = "Internal server error"),
869+
)
870+
)]
871+
/// Update the metadata for a media record. This is a full update, so any existing metadata
872+
/// will be replaced with the new metadata.
873+
pub(crate) async fn put_media_metadata(
874+
Path(id): Path<String>,
875+
State(ctx): State<AppState>,
876+
Extension(req): Extension<RequestContext>,
877+
Json(metadata): Json<MediaMetadata>,
878+
) -> APIResult<Json<MediaMetadata>> {
879+
req.enforce_permissions(&[UserPermission::ManageLibrary])?;
880+
881+
let db = &ctx.db;
882+
let user = req.user();
883+
let age_restrictions = user
884+
.age_restriction
885+
.as_ref()
886+
.map(|ar| apply_media_age_restriction(ar.age, ar.restrict_on_unset));
887+
let where_params = chain_optional_iter(
888+
[media::id::equals(id.clone())]
889+
.into_iter()
890+
.chain(apply_media_library_not_hidden_for_user_filter(user))
891+
.collect::<Vec<WhereParam>>(),
892+
[age_restrictions],
893+
);
894+
895+
let book = db
896+
.media()
897+
.find_first(where_params.clone())
898+
.select(media_id_select::select())
899+
.exec()
900+
.await?
901+
.ok_or(APIError::NotFound(String::from("Media not found")))?;
902+
903+
let set_params = metadata.into_prisma();
904+
905+
let meta = db
906+
.media_metadata()
907+
.upsert(
908+
media_metadata::media_id::equals(id.clone()),
909+
set_params
910+
.clone()
911+
.into_iter()
912+
.chain(vec![media_metadata::media::connect(media::id::equals(
913+
book.id.clone(),
914+
))])
915+
.collect::<Vec<_>>(),
916+
set_params.clone(),
917+
)
918+
.exec()
919+
.await?;
920+
921+
Ok(Json(MediaMetadata::from(meta)))
922+
}

apps/server/src/routers/api/v1/media/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ pub(crate) fn mount(app_state: AppState) -> Router<AppState> {
5050
.route(
5151
"/page/:page/dimensions",
5252
get(individual::get_media_page_dimensions),
53+
)
54+
.route(
55+
"/metadata",
56+
get(individual::get_media_metadata)
57+
.put(individual::put_media_metadata),
5358
),
5459
)
5560
.layer(middleware::from_fn_with_state(app_state, auth_middleware))

apps/server/src/routers/api/v1/user.rs

+2
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ async fn update_preferences(
400400
input.enable_replace_primary_sidebar,
401401
),
402402
user_preferences::enable_hide_scrollbar::set(input.enable_hide_scrollbar),
403+
user_preferences::enable_job_overlay::set(input.enable_job_overlay),
403404
user_preferences::prefer_accent_color::set(input.prefer_accent_color),
404405
user_preferences::show_thumbnails_in_headers::set(
405406
input.show_thumbnails_in_headers,
@@ -572,6 +573,7 @@ pub struct UpdateUserPreferences {
572573
pub enable_double_sidebar: bool,
573574
pub enable_replace_primary_sidebar: bool,
574575
pub enable_hide_scrollbar: bool,
576+
pub enable_job_overlay: bool,
575577
pub prefer_accent_color: bool,
576578
pub show_thumbnails_in_headers: bool,
577579
}

0 commit comments

Comments
 (0)