From 0ceff1794316674440980cbf34c91b0bf46b8e9f Mon Sep 17 00:00:00 2001 From: root Date: Sun, 14 Sep 2025 21:16:38 +0000 Subject: [PATCH] Final 1.0 version of the API --- Cargo.toml | 14 +++++++------- src/middleware/auth.rs | 1 - src/routes.rs | 1 - src/services/converter.rs | 4 +--- src/services/jellyfin.rs | 2 -- src/services/youtube.rs | 2 -- src/utils/env.rs | 1 - 7 files changed, 8 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c4072cb..3d802b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "apijellyfin" version = "0.1.0" -edition = "2021" # 2024 n’est pas encore stable pour Cargo +edition = "2021" [dependencies] actix-web = "4" @@ -23,13 +23,13 @@ name = "apijellyfin" path = "src/main.rs" [profile.dev] -opt-level = 0 # pas d’optimisation lourde en dev +opt-level = 0 debug = true -incremental = true # compile uniquement ce qui change -codegen-units = 16 # compile en parallèle (plus rapide sur CPU multi-core) +incremental = true +codegen-units = 16 [profile.release] opt-level = 3 -lto = "thin" # link-time optimization rapide -codegen-units = 1 # meilleur binaire, plus lent à compiler -strip = "debuginfo" # supprime les symboles pour réduire la taille +lto = "thin" +codegen-units = 1 +strip = "debuginfo" diff --git a/src/middleware/auth.rs b/src/middleware/auth.rs index 2d5ca96..c2703bb 100644 --- a/src/middleware/auth.rs +++ b/src/middleware/auth.rs @@ -68,7 +68,6 @@ where } } -/// Réponse 401 factorisée fn unauthorized(req: ServiceRequest, msg: &str) -> Result, Error> where B: MessageBody + 'static, diff --git a/src/routes.rs b/src/routes.rs index 2b96d7f..2cec8c0 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -2,7 +2,6 @@ use actix_web::web; use crate::handlers::download; -/// Configuration des routes de l'API pub fn config(cfg: &mut web::ServiceConfig) { cfg.service( web::scope("/api") diff --git a/src/services/converter.rs b/src/services/converter.rs index ea6516f..5990e28 100644 --- a/src/services/converter.rs +++ b/src/services/converter.rs @@ -5,12 +5,10 @@ use anyhow::{Result, Context}; pub async fn convert_file(input: &str, format: &str) -> Result { let input_path = Path::new(input); - // Vérifie si l’extension est déjà correcte if input_path.extension().and_then(|ext| ext.to_str()) == Some(format) { return Ok(input.to_string()); // rien à faire } - // Sinon, on génère un nouveau fichier let stem = input_path .file_stem() .ok_or_else(|| anyhow::anyhow!("Nom de fichier invalide"))? @@ -19,7 +17,7 @@ pub async fn convert_file(input: &str, format: &str) -> Result { let output_file = format!("/tmp/{}.{}", stem, format); let status = Command::new("ffmpeg") - .arg("-y") // overwrite + .arg("-y") .arg("-i").arg(input) .arg(&output_file) .status() diff --git a/src/services/jellyfin.rs b/src/services/jellyfin.rs index 8f2ade9..ad57298 100644 --- a/src/services/jellyfin.rs +++ b/src/services/jellyfin.rs @@ -2,7 +2,6 @@ use anyhow::{Result, Context}; use std::process::Command; use reqwest; -/// Upload un fichier vers Jellyfin via rsync+SSH et rafraîchit la médiathèque pub async fn upload_to_jellyfin( file_path: &str, jellyfin_host: &str, @@ -12,7 +11,6 @@ pub async fn upload_to_jellyfin( jellyfin_url: &str, jellyfin_api_key: &str, ) -> Result<()> { - // Transfert du fichier avec rsync let output = Command::new("rsync") .args([ "-avz", diff --git a/src/services/youtube.rs b/src/services/youtube.rs index 3a3f21c..91655b6 100644 --- a/src/services/youtube.rs +++ b/src/services/youtube.rs @@ -5,7 +5,6 @@ use std::str; pub async fn download_from_youtube(url: &str, format: &str) -> Result { let output_template = format!("/tmp/%(title)s-%(uploader)s.{}", format); - // yt-dlp : extrait le fichier ET affiche le chemin final let output = Command::new("yt-dlp") .args([ "-x", @@ -23,7 +22,6 @@ pub async fn download_from_youtube(url: &str, format: &str) -> Result { return Err(anyhow::anyhow!("Échec yt-dlp: {}", stderr)); } - // Récupérer le vrai chemin depuis stdout let filepath = str::from_utf8(&output.stdout) .unwrap_or("") .trim() diff --git a/src/utils/env.rs b/src/utils/env.rs index 21b2468..c7bc80b 100644 --- a/src/utils/env.rs +++ b/src/utils/env.rs @@ -1,6 +1,5 @@ use std::env; -/// Récupère une variable d'environnement avec un fallback par défaut pub fn env_or_default(key: &str, default: &str) -> String { env::var(key).unwrap_or_else(|_| default.to_string()) } \ No newline at end of file