Pokus o opravu souborů v systemd

Tento commit je obsažen v:
sneedmaster 2024-03-03 22:35:43 +01:00
rodič e75e84951e
revize 6071c257b9

Zobrazit soubor

@ -1,9 +1,8 @@
use std::process::Command;
use actix_multipart::form::tempfile::TempFile; use actix_multipart::form::tempfile::TempFile;
use chrono::Utc; use chrono::Utc;
use std::process::Command;
use tokio::{ use tokio::{
fs::{remove_file, rename}, fs::{copy, remove_file},
task::spawn_blocking, task::spawn_blocking,
}; };
@ -67,8 +66,6 @@ impl File {
let timestamp = Utc::now().timestamp_micros(); let timestamp = Utc::now().timestamp_micros();
let format = format.to_owned(); let format = format.to_owned();
let new_name = format!("{timestamp}.{format}");
let (thumb_format, thumb_name) = if thumb { let (thumb_format, thumb_name) = if thumb {
let format = if video { "png".into() } else { format.clone() }; let format = if video { "png".into() } else { format.clone() };
@ -77,15 +74,15 @@ impl File {
(None, None) (None, None)
}; };
rename(temp_file.file.path(), format!("/tmp/{new_name}")).await?; let path = temp_file.file.path().to_string_lossy().to_string();
let (width, height) = if video { let (width, height) = if video {
process_video(cfg, original_name.clone(), new_name.clone(), thumb_name).await? process_video(cfg, original_name.clone(), path.clone(), thumb_name).await?
} else { } else {
process_image(cfg, original_name.clone(), new_name.clone(), thumb_name).await? process_image(cfg, original_name.clone(), path.clone(), thumb_name).await?
}; };
rename(format!("/tmp/{new_name}"), format!("./uploads/{new_name}")).await?; copy(path, format!("./uploads/{timestamp}.{format}")).await?;
let file = File { let file = File {
original_name, original_name,
@ -134,14 +131,14 @@ impl File {
async fn process_image( async fn process_image(
cfg: &Cfg, cfg: &Cfg,
original_name: String, original_name: String,
new_name: String, path: String,
thumb_name: Option<String>, thumb_name: Option<String>,
) -> Result<(u32, u32), NekrochanError> { ) -> Result<(u32, u32), NekrochanError> {
let new_name_ = new_name.clone(); let path_ = path.clone();
let identify_out = spawn_blocking(move || { let identify_out = spawn_blocking(move || {
Command::new("identify") Command::new("identify")
.args(["-format", "%wx%h", &format!("/tmp/{new_name_}[0]")]) .args(["-format", "%wx%h", &format!("{path_}[0]")])
.output() .output()
}) })
.await??; .await??;
@ -181,7 +178,7 @@ async fn process_image(
let output = spawn_blocking(move || { let output = spawn_blocking(move || {
Command::new("convert") Command::new("convert")
.arg(&format!("/tmp/{new_name}")) .arg(path)
.arg("-coalesce") .arg("-coalesce")
.arg("-thumbnail") .arg("-thumbnail")
.arg(&format!("{thumb_size}x{thumb_size}>")) .arg(&format!("{thumb_size}x{thumb_size}>"))
@ -205,10 +202,10 @@ async fn process_image(
async fn process_video( async fn process_video(
cfg: &Cfg, cfg: &Cfg,
original_name: String, original_name: String,
new_name: String, path: String,
thumb_name: Option<String>, thumb_name: Option<String>,
) -> Result<(u32, u32), NekrochanError> { ) -> Result<(u32, u32), NekrochanError> {
let new_name_ = new_name.clone(); let path_ = path.clone();
let ffprobe_out = spawn_blocking(move || { let ffprobe_out = spawn_blocking(move || {
Command::new("ffprobe") Command::new("ffprobe")
@ -221,7 +218,7 @@ async fn process_video(
"stream=width,height", "stream=width,height",
"-of", "-of",
"csv=s=x:p=0", "csv=s=x:p=0",
&format!("/tmp/{new_name_}"), &path_,
]) ])
.output() .output()
}) })
@ -271,7 +268,7 @@ async fn process_video(
Command::new("ffmpeg") Command::new("ffmpeg")
.args([ .args([
"-i", "-i",
&format!("/tmp/{new_name}"), &path,
"-ss", "-ss",
"00:00:00.50", "00:00:00.50",
"-vframes", "-vframes",