updated github actions workflow

This commit is contained in:
Vomitblood 2024-08-08 00:35:49 +08:00
parent de471c3f73
commit 8cc4f0bcbc
2 changed files with 35 additions and 34 deletions

View file

@ -32,6 +32,9 @@ jobs:
- name: Install dependencies for Tauri - name: Install dependencies for Tauri
run: apt install -y cargo libwebkit2gtk-4.0-dev build-essential curl wget file libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev run: apt install -y cargo libwebkit2gtk-4.0-dev build-essential curl wget file libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev
- name: Update Rust
run: rustup update
- name: Install mise - name: Install mise
run: | run: |
install -dm 755 /etc/apt/keyrings install -dm 755 /etc/apt/keyrings

View file

@ -23,36 +23,36 @@ enum ImageType {
// // determine the file format // // determine the file format
// } // }
// fn determine_image_type(file_path: &std::path::Path) -> Result<ImageType, String> { /// Determines the image type of the file at the given path.
// // open the file /// Returns `Ok(ImageType)` on success, or an `Err(String)` if there is an error.
// let mut file = fn determine_image_type(file_path: &std::path::Path) -> Result<ImageType, String> {
// std::fs::File::open(file_path).map_err(|e| format!("Failed to open file: {e}"))?; // Open the file
let mut file =
std::fs::File::open(file_path).map_err(|e| format!("Failed to open file: {e}"))?;
// // read the first few bytes to determine the format // Read the first few bytes to determine the format
// let mut buffer = [0; 12]; let mut buffer = [0; 12];
// file.read_exact(&mut buffer) std::io::Read::read_exact(&mut file, &mut buffer)
// .map_err(|e| format!("Failed to read file: {e}"))?; .map_err(|e| format!("Failed to read file: {e}"))?;
// // check statis formats // Check static formats using the image crate
// if let Some(format) = image::guess_format(&buffer).ok() { match image::guess_format(&buffer) {
// match format { Ok(image::ImageFormat::Jpeg) => Ok(ImageType::Jpeg),
// image::ImageFormat::Jpeg => return Ok(ImageType::Jpeg), Ok(image::ImageFormat::Png) => Ok(ImageType::Png),
// image::ImageFormat::Png => return Ok(ImageType::Png), Ok(image::ImageFormat::Gif) => Ok(ImageType::Gif),
// image::ImageFormat::Gif => return Ok(ImageType::Gif), Ok(image::ImageFormat::WebP) => {
// image::ImageFormat::WebP => { // Additional check for animation in WebP
// // additional check if is animated is_animated_webp(file_path).map(|animated| {
// if is_animated_webp(file_path) { if animated {
// return Ok(ImageType::AnimatedWebP); ImageType::AnimatedWebP
// } else { } else {
// return Ok(ImageType::WebP); ImageType::WebP
// } }
// } })
// _ => return Ok(ImageType::Unsupported), }
// } _ => Ok(ImageType::Unsupported),
// } else { }
// return Ok(ImageType::Unsupported); }
// }
// }
/// check if the file is a valid webp image and if it is animated /// check if the file is a valid webp image and if it is animated
/// returns `Ok(true)` if it is animated, `Ok(false)` if it is not /// returns `Ok(true)` if it is animated, `Ok(false)` if it is not
@ -70,13 +70,11 @@ fn is_animated_webp(file_path: &std::path::Path) -> Result<bool, String> {
.map(|anim| anim.has_animation()) .map(|anim| anim.has_animation())
.map_err(|_| "File is not a valid WebP image".to_string()) .map_err(|_| "File is not a valid WebP image".to_string())
} }
fn main() { fn main() {
// Example usage // Example usage
let path = std::path::Path::new("/home/vomitblood/Downloads/Win10_22H2_English_x64v1.iso"); let path = std::path::Path::new("path/to/your/image.webp");
match is_animated_webp(path) { match determine_image_type(&path) {
Ok(true) => println!("The WebP is animated."), Ok(image_type) => println!("Image type: {:?}", image_type),
Ok(false) => println!("The WebP is not animated."), Err(e) => println!("Error determining image type: {}", e),
Err(e) => println!("Error: {}", e),
} }
} }