Skip to content
Open
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
34 changes: 31 additions & 3 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ path = "src/main.rs"
askama = "0.15"
# askama_web::WebTemplate implements axum::IntoResponse
askama_web = { version = "0.15", features = ["axum-0.8"] }
axum = { version = "0.8.8", features = ["macros"] }
axum = { version = "0.8.8", features = ["macros","multipart"] }
axum-extra = { version = "0.12.1", features = ["cookie"] }
# UTF-8 paths for easier String/PathBuf interop
camino = { version = "1.1.12", features = ["serde1"] }
Expand All @@ -36,7 +36,8 @@ env_logger = "0.11.8"
# Interactions with the torrent client
# Comment/uncomment below for development version
# hightorrent_api = { path = "../hightorrent_api" }
hightorrent_api = { git = "https://github.com/angrynode/hightorrent_api" }
hightorrent_api = { git = "https://github.com/angrynode/hightorrent_api", branch = "feat-sea-orm", features = [ "sea_orm" ]}
itertools = "0.14.0"
# hightorrent_api = "0.2"
log = "0.4.27"
# SQLite ORM
Expand Down
24 changes: 21 additions & 3 deletions src/database/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use sea_orm::entity::prelude::*;
use sea_orm::*;
use snafu::prelude::*;

use crate::database::operation::*;
use crate::database::operator::DatabaseOperator;
use crate::database::{content_folder, operation::*};
use crate::database::{content_folder, magnet};
use crate::extractors::normalized_path::*;
use crate::extractors::user::User;
use crate::routes::category::CategoryForm;
Expand All @@ -27,7 +28,9 @@ pub struct Model {
#[sea_orm(unique)]
pub path: NormalizedPathAbsolute,
#[sea_orm(has_many)]
pub content_folders: HasMany<super::content_folder::Entity>,
pub content_folders: HasMany<content_folder::Entity>,
#[sea_orm(has_many)]
pub magnets: HasMany<magnet::Entity>,
}

#[async_trait::async_trait]
Expand All @@ -48,6 +51,8 @@ pub enum CategoryError {
DB { source: sea_orm::DbErr },
#[snafu(display("The category (ID: {id}) does not exist"))]
IDNotFound { id: i32 },
#[snafu(display("The category id is invalid: {id}"))]
IDInvalid { id: String },
#[snafu(display("The category (Name: {name}) does not exist"))]
NameNotFound { name: String },
#[snafu(display("Failed to save the operation log"))]
Expand Down Expand Up @@ -84,7 +89,7 @@ impl CategoryOperator {

/// Find one category by ID
///
/// Should not fail, unless SQLite was corrupted for some reason.
/// Fails if the requested category ID does not exist.
pub async fn find_by_id(&self, id: i32) -> Result<Model, CategoryError> {
let category = Entity::find_by_id(id)
.one(&self.state.database)
Expand All @@ -97,6 +102,19 @@ impl CategoryOperator {
}
}

/// Find one category by stringy ID
///
/// Fails if:
///
/// - the requested ID does not exist
/// - the requested ID could not be parsed
pub async fn find_by_id_str(&self, id: &str) -> Result<Model, CategoryError> {
let id: i32 = id
.parse()
.map_err(|_e| CategoryError::IDInvalid { id: id.to_string() })?;
self.find_by_id(id).await
}

/// Find one category by Name
///
/// Should not fail, unless SQLite was corrupted for some reason.
Expand Down
17 changes: 17 additions & 0 deletions src/database/content_folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub struct Model {
pub parent_id: Option<i32>,
#[sea_orm(self_ref, relation_enum = "Parent", from = "parent_id", to = "id")]
pub parent: HasOne<Entity>,
#[sea_orm(has_many)]
pub magnets: HasMany<super::magnet::Entity>,
}

#[async_trait::async_trait]
Expand All @@ -46,6 +48,8 @@ pub enum ContentFolderError {
PathTaken { path: String },
#[snafu(display("The Content Folder (Path: {path}) does not exist"))]
NotFound { path: String },
#[snafu(display("The content folder id is invalid: {id}"))]
IDInvalid { id: String },
#[snafu(display("Database error"))]
DB { source: sea_orm::DbErr },
#[snafu(display("Failed to save the operation log"))]
Expand Down Expand Up @@ -118,6 +122,19 @@ impl ContentFolderOperator {
}
}

/// Find one category by stringy ID
///
/// Fails if:
///
/// - the requested ID does not exist
/// - the requested ID could not be parsed
pub async fn find_by_id_str(&self, id: &str) -> Result<Model, ContentFolderError> {
let id: i32 = id
.parse()
.map_err(|_e| ContentFolderError::IDInvalid { id: id.to_string() })?;
self.find_by_id(id).await
}

/// Create a new content folder
///
/// Fails if:
Expand Down
Loading