chore: solve clippy warnings, export directly into bindings/ dir, remove unreachable expression arms

This commit is contained in:
Ryan Walters
2025-08-20 02:35:30 -05:00
parent ecc8380645
commit 8069d5a061
3 changed files with 14 additions and 13 deletions

View File

@@ -5,7 +5,7 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "tsc && vite build", "build": "pnpm generate-types && tsc && vite build",
"preview": "vite preview", "preview": "vite preview",
"tauri": "tauri", "tauri": "tauri",
"generate-types": "tsx scripts/generate-types.ts" "generate-types": "tsx scripts/generate-types.ts"

View File

@@ -2,10 +2,10 @@ mod ff;
mod media; mod media;
mod models; mod models;
use std::path::Path;
use models::{MediaType, StreamDetail, StreamResult, StreamResultError};
use media::{detect_media_type, is_media_file};
use ff::extract_streams; use ff::extract_streams;
use media::{detect_media_type, is_media_file};
use models::{StreamResult, StreamResultError};
use std::path::Path;
// detection, helpers moved to modules above // detection, helpers moved to modules above
@@ -68,10 +68,10 @@ fn has_streams(paths: Vec<String>) -> Result<Vec<StreamResult>, StreamResultErro
}) })
} }
Err(err) => { Err(err) => {
eprintln!("Could not analyze media file with ffprobe: {:?}", err); eprintln!("Could not analyze media file with ffprobe: {err:?}");
Err(StreamResultError { Err(StreamResultError {
filename: Some(filename), filename: Some(filename),
reason: format!("Could not analyze media file: {}", err), reason: format!("Could not analyze media file: {err}"),
error_type: "analysis_failed".to_string(), error_type: "analysis_failed".to_string(),
}) })
} }
@@ -80,7 +80,7 @@ fn has_streams(paths: Vec<String>) -> Result<Vec<StreamResult>, StreamResultErro
// For non-media files, return an error indicating it's not a media file // For non-media files, return an error indicating it's not a media file
Err(StreamResultError { Err(StreamResultError {
filename: Some(filename), filename: Some(filename),
reason: format!("Not a media file (detected as {:?})", media_type), reason: format!("Not a media file (detected as {media_type:?})"),
error_type: "not_media".to_string(), error_type: "not_media".to_string(),
}) })
} }
@@ -99,13 +99,14 @@ pub fn run() {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::models::StreamDetail;
use super::*; use super::*;
use ts_rs::TS;
#[test] #[test]
fn export_bindings() { fn export_bindings() {
// This will generate TypeScript bindings when you run `cargo test export_bindings` // This will generate TypeScript bindings when you run `cargo test export_bindings`
StreamResult::export().unwrap(); TS::export_all_to("../../src/bindings")
StreamDetail::export().unwrap();
StreamResultError::export().unwrap();
} }
} }

View File

@@ -117,11 +117,11 @@ pub fn detect_media_type(path: &Path) -> MediaType {
// Archive extensions // Archive extensions
"zip" | "rar" | "7z" | "tar" | "gz" | "bz2" | "bz3" | "xz" | "swf" | "sqlite" "zip" | "rar" | "7z" | "tar" | "gz" | "bz2" | "bz3" | "xz" | "swf" | "sqlite"
| "nes" | "crx" | "cab" | "deb" | "ar" | "Z" | "lz" | "rpm" | "dcm" | "zst" | "lz4" | "nes" | "crx" | "cab" | "deb" | "ar" | "Z" | "lz" | "rpm" | "dcm" | "zst" | "lz4"
| "msi" | "cpio" | "par2" | "epub" | "mobi" => MediaType::Archive, | "cpio" | "par2" | "epub" | "mobi" => MediaType::Archive,
// Executable extensions // Executable extensions
"exe" | "dll" | "msi" | "dmg" | "pkg" | "deb" | "rpm" | "app" | "elf" | "bc" "exe" | "dll" | "msi" | "dmg" | "pkg" | "app" | "elf" | "bc" | "mach" | "class"
| "mach" | "class" | "dex" | "dey" | "der" | "obj" => MediaType::Executable, | "dex" | "dey" | "der" | "obj" => MediaType::Executable,
// Library extensions // Library extensions
"so" | "dylib" => MediaType::Library, "so" | "dylib" => MediaType::Library,