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]
|
[package]
|
||||||
name = "apijellyfin"
|
name = "apijellyfin"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021" # 2024 n’est pas encore stable pour Cargo
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "4"
|
actix-web = "4"
|
||||||
@ -23,13 +23,13 @@ name = "apijellyfin"
|
|||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
opt-level = 0 # pas d’optimisation lourde en dev
|
opt-level = 0
|
||||||
debug = true
|
debug = true
|
||||||
incremental = true # compile uniquement ce qui change
|
incremental = true
|
||||||
codegen-units = 16 # compile en parallèle (plus rapide sur CPU multi-core)
|
codegen-units = 16
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
lto = "thin" # link-time optimization rapide
|
lto = "thin"
|
||||||
codegen-units = 1 # meilleur binaire, plus lent à compiler
|
codegen-units = 1
|
||||||
strip = "debuginfo" # supprime les symboles pour réduire la taille
|
strip = "debuginfo"
|
||||||
|
|||||||
@ -68,7 +68,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Réponse 401 factorisée
|
|
||||||
fn unauthorized<B>(req: ServiceRequest, msg: &str) -> Result<ServiceResponse<BoxBody>, Error>
|
fn unauthorized<B>(req: ServiceRequest, msg: &str) -> Result<ServiceResponse<BoxBody>, Error>
|
||||||
where
|
where
|
||||||
B: MessageBody + 'static,
|
B: MessageBody + 'static,
|
||||||
|
|||||||
@ -2,7 +2,6 @@ use actix_web::web;
|
|||||||
|
|
||||||
use crate::handlers::download;
|
use crate::handlers::download;
|
||||||
|
|
||||||
/// Configuration des routes de l'API
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(
|
cfg.service(
|
||||||
web::scope("/api")
|
web::scope("/api")
|
||||||
|
|||||||
@ -5,12 +5,10 @@ use anyhow::{Result, Context};
|
|||||||
pub async fn convert_file(input: &str, format: &str) -> Result<String> {
|
pub async fn convert_file(input: &str, format: &str) -> Result<String> {
|
||||||
let input_path = Path::new(input);
|
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) {
|
if input_path.extension().and_then(|ext| ext.to_str()) == Some(format) {
|
||||||
return Ok(input.to_string()); // rien à faire
|
return Ok(input.to_string()); // rien à faire
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sinon, on génère un nouveau fichier
|
|
||||||
let stem = input_path
|
let stem = input_path
|
||||||
.file_stem()
|
.file_stem()
|
||||||
.ok_or_else(|| anyhow::anyhow!("Nom de fichier invalide"))?
|
.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 output_file = format!("/tmp/{}.{}", stem, format);
|
||||||
|
|
||||||
let status = Command::new("ffmpeg")
|
let status = Command::new("ffmpeg")
|
||||||
.arg("-y") // overwrite
|
.arg("-y")
|
||||||
.arg("-i").arg(input)
|
.arg("-i").arg(input)
|
||||||
.arg(&output_file)
|
.arg(&output_file)
|
||||||
.status()
|
.status()
|
||||||
|
|||||||
@ -2,7 +2,6 @@ use anyhow::{Result, Context};
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use reqwest;
|
use reqwest;
|
||||||
|
|
||||||
/// Upload un fichier vers Jellyfin via rsync+SSH et rafraîchit la médiathèque
|
|
||||||
pub async fn upload_to_jellyfin(
|
pub async fn upload_to_jellyfin(
|
||||||
file_path: &str,
|
file_path: &str,
|
||||||
jellyfin_host: &str,
|
jellyfin_host: &str,
|
||||||
@ -12,7 +11,6 @@ pub async fn upload_to_jellyfin(
|
|||||||
jellyfin_url: &str,
|
jellyfin_url: &str,
|
||||||
jellyfin_api_key: &str,
|
jellyfin_api_key: &str,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// Transfert du fichier avec rsync
|
|
||||||
let output = Command::new("rsync")
|
let output = Command::new("rsync")
|
||||||
.args([
|
.args([
|
||||||
"-avz",
|
"-avz",
|
||||||
|
|||||||
@ -5,7 +5,6 @@ use std::str;
|
|||||||
pub async fn download_from_youtube(url: &str, format: &str) -> Result<String> {
|
pub async fn download_from_youtube(url: &str, format: &str) -> Result<String> {
|
||||||
let output_template = format!("/tmp/%(title)s-%(uploader)s.{}", format);
|
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")
|
let output = Command::new("yt-dlp")
|
||||||
.args([
|
.args([
|
||||||
"-x",
|
"-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));
|
return Err(anyhow::anyhow!("Échec yt-dlp: {}", stderr));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Récupérer le vrai chemin depuis stdout
|
|
||||||
let filepath = str::from_utf8(&output.stdout)
|
let filepath = str::from_utf8(&output.stdout)
|
||||||
.unwrap_or("")
|
.unwrap_or("")
|
||||||
.trim()
|
.trim()
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
use std::env;
|
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 {
|
pub fn env_or_default(key: &str, default: &str) -> String {
|
||||||
env::var(key).unwrap_or_else(|_| default.to_string())
|
env::var(key).unwrap_or_else(|_| default.to_string())
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user