Final 1.0 version of the API
This commit is contained in:
parent
91193e71f6
commit
0ceff17943
14
Cargo.toml
14
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"
|
||||
|
||||
@ -68,7 +68,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Réponse 401 factorisée
|
||||
fn unauthorized<B>(req: ServiceRequest, msg: &str) -> Result<ServiceResponse<BoxBody>, Error>
|
||||
where
|
||||
B: MessageBody + 'static,
|
||||
|
||||
@ -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")
|
||||
|
||||
@ -5,12 +5,10 @@ use anyhow::{Result, Context};
|
||||
pub async fn convert_file(input: &str, format: &str) -> Result<String> {
|
||||
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<String> {
|
||||
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()
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -5,7 +5,6 @@ use std::str;
|
||||
pub async fn download_from_youtube(url: &str, format: &str) -> Result<String> {
|
||||
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<String> {
|
||||
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()
|
||||
|
||||
@ -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())
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user