Pokus o opravu souborů v systemd
Tento commit je obsažen v:
rodič
e75e84951e
revize
6071c257b9
31
src/files.rs
31
src/files.rs
@ -1,9 +1,8 @@
|
||||
use std::process::Command;
|
||||
|
||||
use actix_multipart::form::tempfile::TempFile;
|
||||
use chrono::Utc;
|
||||
use std::process::Command;
|
||||
use tokio::{
|
||||
fs::{remove_file, rename},
|
||||
fs::{copy, remove_file},
|
||||
task::spawn_blocking,
|
||||
};
|
||||
|
||||
@ -67,8 +66,6 @@ impl File {
|
||||
let timestamp = Utc::now().timestamp_micros();
|
||||
let format = format.to_owned();
|
||||
|
||||
let new_name = format!("{timestamp}.{format}");
|
||||
|
||||
let (thumb_format, thumb_name) = if thumb {
|
||||
let format = if video { "png".into() } else { format.clone() };
|
||||
|
||||
@ -77,15 +74,15 @@ impl File {
|
||||
(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 {
|
||||
process_video(cfg, original_name.clone(), new_name.clone(), thumb_name).await?
|
||||
process_video(cfg, original_name.clone(), path.clone(), thumb_name).await?
|
||||
} 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 {
|
||||
original_name,
|
||||
@ -134,14 +131,14 @@ impl File {
|
||||
async fn process_image(
|
||||
cfg: &Cfg,
|
||||
original_name: String,
|
||||
new_name: String,
|
||||
path: String,
|
||||
thumb_name: Option<String>,
|
||||
) -> Result<(u32, u32), NekrochanError> {
|
||||
let new_name_ = new_name.clone();
|
||||
let path_ = path.clone();
|
||||
|
||||
let identify_out = spawn_blocking(move || {
|
||||
Command::new("identify")
|
||||
.args(["-format", "%wx%h", &format!("/tmp/{new_name_}[0]")])
|
||||
.args(["-format", "%wx%h", &format!("{path_}[0]")])
|
||||
.output()
|
||||
})
|
||||
.await??;
|
||||
@ -181,7 +178,7 @@ async fn process_image(
|
||||
|
||||
let output = spawn_blocking(move || {
|
||||
Command::new("convert")
|
||||
.arg(&format!("/tmp/{new_name}"))
|
||||
.arg(path)
|
||||
.arg("-coalesce")
|
||||
.arg("-thumbnail")
|
||||
.arg(&format!("{thumb_size}x{thumb_size}>"))
|
||||
@ -205,10 +202,10 @@ async fn process_image(
|
||||
async fn process_video(
|
||||
cfg: &Cfg,
|
||||
original_name: String,
|
||||
new_name: String,
|
||||
path: String,
|
||||
thumb_name: Option<String>,
|
||||
) -> Result<(u32, u32), NekrochanError> {
|
||||
let new_name_ = new_name.clone();
|
||||
let path_ = path.clone();
|
||||
|
||||
let ffprobe_out = spawn_blocking(move || {
|
||||
Command::new("ffprobe")
|
||||
@ -221,7 +218,7 @@ async fn process_video(
|
||||
"stream=width,height",
|
||||
"-of",
|
||||
"csv=s=x:p=0",
|
||||
&format!("/tmp/{new_name_}"),
|
||||
&path_,
|
||||
])
|
||||
.output()
|
||||
})
|
||||
@ -271,7 +268,7 @@ async fn process_video(
|
||||
Command::new("ffmpeg")
|
||||
.args([
|
||||
"-i",
|
||||
&format!("/tmp/{new_name}"),
|
||||
&path,
|
||||
"-ss",
|
||||
"00:00:00.50",
|
||||
"-vframes",
|
||||
|
Načítá se…
Odkázat v novém úkolu
Zablokovat Uživatele