2023-07-13 03:12:21 +00:00
|
|
|
mod exiftool;
|
|
|
|
mod ffmpeg;
|
|
|
|
mod magick;
|
|
|
|
|
|
|
|
use actix_web::web::Bytes;
|
|
|
|
|
2024-02-01 03:32:01 +00:00
|
|
|
use crate::{formats::InputFile, magick::PolicyDir, tmp_file::TmpDir};
|
2023-07-13 03:12:21 +00:00
|
|
|
|
2023-07-13 19:34:40 +00:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2023-07-13 03:12:21 +00:00
|
|
|
pub(crate) struct Discovery {
|
|
|
|
pub(crate) input: InputFile,
|
|
|
|
pub(crate) width: u16,
|
|
|
|
pub(crate) height: u16,
|
|
|
|
pub(crate) frames: Option<u32>,
|
|
|
|
}
|
|
|
|
|
2023-07-14 00:21:57 +00:00
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
|
|
pub(crate) enum DiscoverError {
|
|
|
|
#[error("No frames in uploaded media")]
|
|
|
|
NoFrames,
|
|
|
|
|
|
|
|
#[error("Not all frames have same image format")]
|
|
|
|
FormatMismatch,
|
|
|
|
|
|
|
|
#[error("Input file type {0} is unsupported")]
|
|
|
|
UnsupportedFileType(String),
|
|
|
|
}
|
|
|
|
|
2023-12-16 04:34:45 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip_all)]
|
2023-08-05 17:41:06 +00:00
|
|
|
pub(crate) async fn discover_bytes(
|
2023-10-07 16:32:36 +00:00
|
|
|
tmp_dir: &TmpDir,
|
2024-02-01 03:32:01 +00:00
|
|
|
policy_dir: &PolicyDir,
|
2023-08-05 17:41:06 +00:00
|
|
|
timeout: u64,
|
|
|
|
bytes: Bytes,
|
|
|
|
) -> Result<Discovery, crate::error::Error> {
|
2023-10-07 16:32:36 +00:00
|
|
|
let discovery = ffmpeg::discover_bytes(tmp_dir, timeout, bytes.clone()).await?;
|
2023-07-13 03:12:21 +00:00
|
|
|
|
2024-02-01 03:32:01 +00:00
|
|
|
let discovery =
|
|
|
|
magick::confirm_bytes(tmp_dir, policy_dir, discovery, timeout, bytes.clone()).await?;
|
2023-07-13 03:12:21 +00:00
|
|
|
|
2023-08-05 17:41:06 +00:00
|
|
|
let discovery = exiftool::check_reorient(discovery, timeout, bytes).await?;
|
2023-07-13 03:12:21 +00:00
|
|
|
|
|
|
|
Ok(discovery)
|
|
|
|
}
|