Initial code commit
CI / test (push) Successful in 5m7s

This commit is contained in:
IxianPixel committed 2026-11-05 14:19:37 +00:00
1 parent f47217d5a3
commit 8ceb3c8be8
60 files changed
+10884

No files matched your search

+114
View File
@@ -0,0 +1,114 @@
//! Browsing the local Jellyfin libraries.
use std::path::Path;
use jm_jellyfin::ItemQuery;
use serde::{Deserialize, Serialize};
use crate::state::AppState;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Library {
pub id: String,
pub name: String,
pub collection_type: Option<String>,
pub locations: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LibraryItem {
pub id: String,
pub name: String,
/// "Movie" or "Series".
pub kind: String,
pub year: Option<i32>,
pub path: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LocationCheck {
pub library: String,
pub jellyfin_path: String,
pub local_path: String,
pub exists: bool,
pub writable: bool,
}
/// Only libraries jellymove knows how to move items out of.
fn supported(collection_type: Option<&str>) -> bool {
matches!(collection_type, Some("movies") | Some("tvshows") | None)
}
pub async fn libraries(state: &AppState) -> anyhow::Result<Vec<Library>> {
Ok(state
.jellyfin
.virtual_folders()
.await?
.into_iter()
.filter(|v| supported(v.collection_type.as_deref()))
.map(|v| Library {
id: v.item_id,
name: v.name,
collection_type: v.collection_type,
locations: v.locations,
})
.collect())
}
pub async fn items(
state: &AppState,
library_id: &str,
search: Option<&str>,
) -> anyhow::Result<Vec<LibraryItem>> {
let search = search.map(str::trim).filter(|s| !s.is_empty());
let items = state
.jellyfin
.items(&ItemQuery {
parent_id: Some(library_id),
include_types: &["Movie", "Series"],
recursive: true,
search,
..Default::default()
})
.await?;
Ok(items
.into_iter()
.map(|i| LibraryItem {
id: i.id,
name: i.name,
kind: i.kind,
year: i.production_year,
path: i.path,
})
.collect())
}
/// Confirm every library location exists and is writable from this agent.
/// The most common setup mistakes (wrong mount, wrong PUID/PGID, missing
/// path_map) all show up here.
pub async fn check_locations(state: &AppState) -> anyhow::Result<Vec<LocationCheck>> {
let mut out = Vec::new();
for lib in libraries(state).await? {
for loc in &lib.locations {
let local = state.cfg.path_map.to_local(Path::new(loc));
let exists = tokio::fs::metadata(&local)
.await
.map(|m| m.is_dir())
.unwrap_or(false);
let writable = exists && {
let probe = local.join(format!(".jellymove-probe-{}", uuid::Uuid::new_v4()));
let ok = tokio::fs::write(&probe, b"").await.is_ok();
let _ = tokio::fs::remove_file(&probe).await;
ok
};
out.push(LocationCheck {
library: lib.name.clone(),
jellyfin_path: loc.clone(),
local_path: local.display().to_string(),
exists,
writable,
});
}
}
Ok(out)
}