Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route fixes caught in more thorough testing #586

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dim-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
//! It uses Diesel as the ORM and rocket for the http/s server
//!
//! The project is split up into several crates:
//! * [`database`](database) - Holds all the database models including some frequently used db operations
//! * [`database`](dim-database) - Holds all the database models including some frequently used db operations
//! * [`routes`](routes) - All of the routes that we expose over http are stored in there
//! * [`scanners`](scanners) - The filesystem scanner and daemon code is located here
//! * [`scanners`](scanner) - The filesystem scanner and daemon code is located here
//! ffmpeg that is used by several parts of dim
//!
//! # Building
Expand Down
6 changes: 3 additions & 3 deletions dim-database/src/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ impl PartialEq for Media {

impl Media {
/// Method returns all Media objects associated with a Library. Its exactly the same as
/// [`Library::get`](Library::get) except it takes in a Library object instead of a id.
/// [`Library::get`](Library::get) is a intermediary to this function, as it calls this
/// [`Library::get`](dim-database::library::Library::get) except it takes in a Library object instead of a id.
/// [`Library::get`](dim-database::library::Library::get) is a intermediary to this function, as it calls this
/// function.
///
/// # Arguments
/// * `conn` - mutable reference to a sqlx transaction.
/// * `library_id` - a [`Library`](Library) id.
/// * `library_id` - a [`Library`](dim-database::library::Library) id.
pub async fn get_all(
conn: &mut crate::Transaction<'_>,
library_id: i64,
Expand Down
8 changes: 4 additions & 4 deletions dim-database/src/mediafile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use std::iter::repeat;
pub struct MediaFile {
/// Unique identifier of a mediafile.
pub id: i64,
/// Foreign key linking this entry to the media table or [`Media`](Media) struct
/// Foreign key linking this entry to the media table or [`Media`] struct
pub media_id: Option<i64>,
/// Library foreign key linking this entry to the library table or [`Library`](Library) struct
/// Library foreign key linking this entry to the library table or [`Library`](dim-database::library::Library) struct
pub library_id: i64,
/// String representing the file path of the file we target. This should be a real path on the
/// filesystem.
Expand Down Expand Up @@ -243,7 +243,7 @@ impl MediaFile {
}
}

/// Same as [`MediaFile`](MediaFile) except its missing the id field.
/// Same as [`MediaFile`] except its missing the id field.
#[derive(Clone, Serialize, Debug, Default)]
pub struct InsertableMediaFile {
pub media_id: Option<i64>,
Expand Down Expand Up @@ -322,7 +322,7 @@ impl InsertableMediaFile {
}
}

/// Same as [`MediaFile`](MediaFile) except its missing the id and library_id fields. Everything is
/// Same as [`MediaFile`] except its missing the id and library_id fields. Everything is
/// optional too.
#[derive(Clone, Default, Deserialize, PartialEq, Debug)]
pub struct UpdateMediaFile {
Expand Down
2 changes: 1 addition & 1 deletion dim-database/src/season.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl Season {
}

/// Struct representing a insertable season
/// Its exactly the same as [`Season`](Season) except it misses the tvshowid field and the id
/// Its exactly the same as [`Season`] except it misses the tvshowid field and the id
/// field.
#[derive(Clone, Serialize, Deserialize, Default)]
pub struct InsertableSeason {
Expand Down
8 changes: 4 additions & 4 deletions dim-extern-api/src/tmdb/metadata_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,15 +444,15 @@ impl TMDBMetadataProvider {
}
}

// -- TMDBMetadataProviderRef<T>
// -- MetadataProviderOf<T>

/// Used to key [TMDBMetadataProviderRef] to search for TV shows, compliments [Movies].
/// Used to key [`MetadataProviderOf`] to search for TV shows, compliments [Movies].
pub struct TvShows;

/// Used to key [TMDBMetadataProviderRef] to search for movies, compliments [TvShows].
/// Used to key [`MetadataProviderOf`] to search for movies, compliments [TvShows].
pub struct Movies;

/// An instance of [TMDBMetadataProvider] with a generic parameter to infer the [MediaType] for searches.
/// An instance of [`TMDBMetadataProvider`] with a generic parameter to infer the [`MediaType`](dim-database::library::MediaType) for searches.
pub struct MetadataProviderOf<K>
where
K: sealed::AssocMediaTypeConst + Send + Sync + 'static,
Expand Down
24 changes: 12 additions & 12 deletions dim-web/src/routes/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! # Request Authentication and Authorization
//! Most API endpoints require a valid JWT authentication token. If no such token is supplied, the
//! API will return [`Unauthenticated`]. Authentication tokens can be obtained by logging in with
//! API will return [`AuthError`]. Authentication tokens can be obtained by logging in with
//! the [`login`] method. Authentication tokens must be passed to the server through a
//! `Authroization` header.
//!
Expand All @@ -16,7 +16,7 @@
//! By default tokens expire after exactly two weeks, once the tokens expire the client must renew
//! them. At the moment renewing the token is only possible by logging in again.
//!
//! [`Unauthenticated`]: crate::errors::DimError::Unauthenticated
//! [`AuthError`]
//! [`login`]: fn@login

use crate::AppState;
Expand Down Expand Up @@ -103,9 +103,9 @@ impl IntoResponse for AuthError {
/// ```
///
/// # Errors
/// * [`Unauthorized`] - Returned if the authentication token lacks `owner` permissions
/// * [`AuthError`] - Returned if the authentication token lacks `owner` permissions
///
/// [`Unauthorized`]: crate::errors::DimError::Unauthorized
/// [`AuthError`]
pub async fn get_all_invites(
Extension(user): Extension<User>,
State(AppState { conn, .. }): State<AppState>,
Expand Down Expand Up @@ -181,9 +181,9 @@ pub async fn get_all_invites(
/// ```
///
/// # Errors
/// * [`Unauthorized`] - Returned if the authentication token lacks `owner` permissions
/// * [`AuthError`] - Returned if the authentication token lacks `owner` permissions
///
/// [`Unauthorized`]: crate::errors::DimError::Unauthorized
/// [`AuthError`]
pub async fn generate_invite(
Extension(user): Extension<User>,
State(AppState { conn, .. }): State<AppState>,
Expand Down Expand Up @@ -221,9 +221,9 @@ pub async fn generate_invite(
/// If the token was successfully deleted, this route will return `200 0K`.
///
/// # Errors
/// * [`Unauthorized`] - Returned if the authentication token lacks `owner` permissions
/// * [`AuthError`] - Returned if the authentication token lacks `owner` permissions
///
/// [`Unauthorized`]: crate::errors::DimError::Unauthorized
/// [`AuthError`]
pub async fn delete_token(
Extension(user): Extension<User>,
State(AppState { conn, .. }): State<AppState>,
Expand Down Expand Up @@ -338,9 +338,9 @@ impl IntoResponse for LoginError {
/// ```
///
/// # Errors
/// * [`InvalidCredentials`] - The provided username or password is incorrect.
/// * [`LoginError`] - The provided username or password is incorrect.
///
/// [`InvalidCredentials`]: crate::errors::DimError::InvalidCredentials
/// [`LoginError`]
/// [`Login`]: dim_database::user::Login
#[axum::debug_handler]
pub async fn login(
Expand Down Expand Up @@ -421,10 +421,10 @@ impl IntoResponse for RegisterError {
/// ```
///
/// # Errors
/// * [`NoToken`] - Either the request doesnt contain an invite token, or the invite token is
/// * [`RegisterError`] - Either the request doesnt contain an invite token, or the invite token is
/// invalid.
///
/// [`NoToken`]: crate::errors::DimError::NoToken
/// [`RegisterError`]
/// [`Login`]: dim_database::user::Login
#[axum::debug_handler]
pub async fn register(
Expand Down
12 changes: 9 additions & 3 deletions dim-web/src/routes/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use fuzzy_matcher::skim::SkimMatcherV2;
use fuzzy_matcher::FuzzyMatcher;
use http::StatusCode;
use serde::Serialize;
use serde::Deserialize;

use crate::error::DimErrorWrapper;
use crate::AppState;
Expand Down Expand Up @@ -246,13 +247,18 @@ pub async fn library_get_media(State(AppState { conn, .. }): State<AppState>, Pa
Json(result).into_response()
}

/// Method mapped to `GET` /api/v1/library/<id>/unmatched` returns a list of all unmatched medias
#[derive(Deserialize)]
pub struct UnmatchedArgs {
search: Option<String>,
}

/// Method mapped to `GET /api/v1/library/<id>/unmatched` returns a list of all unmatched medias
/// to be displayed in the library pages.
///
pub async fn library_get_unmatched(
State(AppState { conn, .. }): State<AppState>,
Path(id): Path<i64>,
Query(search): Query<Option<String>>,
Query(params): Query<UnmatchedArgs>,
) -> Response {
let mut tx = match conn.read().begin().await {
Ok(tx) => tx,
Expand All @@ -277,7 +283,7 @@ pub async fn library_get_unmatched(
// we want to pre-sort to ensure our tree is somewhat ordered.
files.sort_by(|a, b| a.target_file.cmp(&b.target_file));

if let Some(search) = search {
if let Some(search) = params.search {
let matcher = SkimMatcherV2::default();

let mut matched_files = files
Expand Down
6 changes: 2 additions & 4 deletions dim-web/src/routes/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,7 @@ pub async fn get_init(
/// Method mapped to `/api/v1/stream/<id>/data/<chunk..>` returns a chunk for stream `id`.
pub async fn get_chunk(
State(AppState { state, .. }): State<AppState>,
Path(id): Path<String>,
Path(chunk): Path<PathBuf>,
Path((id, chunk)): Path<(String, PathBuf)>,
) -> Result<impl IntoResponse, errors::StreamingErrors> {
let extension = chunk
.extension()
Expand Down Expand Up @@ -643,8 +642,7 @@ pub async fn get_subtitle_ass(
/// on web platforms.
pub async fn should_client_hard_seek(
State(AppState { state, stream_tracking, .. }): State<AppState>,
Path(gid): Path<String>,
Path(chunk_num): Path<u32>,
Path((gid, chunk_num)): Path<(String, u32)>,
) -> Result<impl IntoResponse, errors::StreamingErrors> {
let gid = match Uuid::parse_str(gid.as_str()) {
Ok(x) => x,
Expand Down
2 changes: 1 addition & 1 deletion dim-web/src/routes/tv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub async fn get_tv_seasons(
Ok(axum::response::Json(json!(&Season::get_all(&mut tx, id).await?)).into_response())
}

/// Method mapped to `GET /api/v1/season/<id>` returns info about the season by <id>
/// Method mapped to `GET /api/v1/season/<id>` returns info about the season by `id`
///
/// # Arguments
/// * `id` - id of the season we want info about
Expand Down
Loading