mirror of
				https://github.com/Vomitblood/stort.git
				synced 2025-11-04 12:47:22 +08:00 
			
		
		
		
	updated github actions workflow
This commit is contained in:
		
							parent
							
								
									de471c3f73
								
							
						
					
					
						commit
						8cc4f0bcbc
					
				
							
								
								
									
										3
									
								
								.github/workflows/build-validation.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.github/workflows/build-validation.yml
									
									
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -32,6 +32,9 @@ jobs:
 | 
			
		|||
      - 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
 | 
			
		||||
 | 
			
		||||
      - name: Update Rust
 | 
			
		||||
        run: rustup update
 | 
			
		||||
 | 
			
		||||
      - name: Install mise
 | 
			
		||||
        run: |
 | 
			
		||||
          install -dm 755 /etc/apt/keyrings
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,36 +23,36 @@ enum ImageType {
 | 
			
		|||
//     // determine the file format
 | 
			
		||||
// }
 | 
			
		||||
 | 
			
		||||
// fn determine_image_type(file_path: &std::path::Path) -> Result<ImageType, String> {
 | 
			
		||||
//     // open the file
 | 
			
		||||
//     let mut file =
 | 
			
		||||
//         std::fs::File::open(file_path).map_err(|e| format!("Failed to open file: {e}"))?;
 | 
			
		||||
/// Determines the image type of the file at the given path.
 | 
			
		||||
/// Returns `Ok(ImageType)` on success, or an `Err(String)` if there is an error.
 | 
			
		||||
fn determine_image_type(file_path: &std::path::Path) -> Result<ImageType, String> {
 | 
			
		||||
    // 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
 | 
			
		||||
//     let mut buffer = [0; 12];
 | 
			
		||||
//     file.read_exact(&mut buffer)
 | 
			
		||||
//         .map_err(|e| format!("Failed to read file: {e}"))?;
 | 
			
		||||
    // Read the first few bytes to determine the format
 | 
			
		||||
    let mut buffer = [0; 12];
 | 
			
		||||
    std::io::Read::read_exact(&mut file, &mut buffer)
 | 
			
		||||
        .map_err(|e| format!("Failed to read file: {e}"))?;
 | 
			
		||||
 | 
			
		||||
//     // check statis formats
 | 
			
		||||
//     if let Some(format) = image::guess_format(&buffer).ok() {
 | 
			
		||||
//         match format {
 | 
			
		||||
//             image::ImageFormat::Jpeg => return Ok(ImageType::Jpeg),
 | 
			
		||||
//             image::ImageFormat::Png => return Ok(ImageType::Png),
 | 
			
		||||
//             image::ImageFormat::Gif => return Ok(ImageType::Gif),
 | 
			
		||||
//             image::ImageFormat::WebP => {
 | 
			
		||||
//                 // additional check if is animated
 | 
			
		||||
//                 if is_animated_webp(file_path) {
 | 
			
		||||
//                     return Ok(ImageType::AnimatedWebP);
 | 
			
		||||
//                 } else {
 | 
			
		||||
//                     return Ok(ImageType::WebP);
 | 
			
		||||
//                 }
 | 
			
		||||
//             }
 | 
			
		||||
//             _ => return Ok(ImageType::Unsupported),
 | 
			
		||||
//         }
 | 
			
		||||
//     } else {
 | 
			
		||||
//         return Ok(ImageType::Unsupported);
 | 
			
		||||
//     }
 | 
			
		||||
// }
 | 
			
		||||
    // Check static formats using the image crate
 | 
			
		||||
    match image::guess_format(&buffer) {
 | 
			
		||||
        Ok(image::ImageFormat::Jpeg) => Ok(ImageType::Jpeg),
 | 
			
		||||
        Ok(image::ImageFormat::Png) => Ok(ImageType::Png),
 | 
			
		||||
        Ok(image::ImageFormat::Gif) => Ok(ImageType::Gif),
 | 
			
		||||
        Ok(image::ImageFormat::WebP) => {
 | 
			
		||||
            // Additional check for animation in WebP
 | 
			
		||||
            is_animated_webp(file_path).map(|animated| {
 | 
			
		||||
                if animated {
 | 
			
		||||
                    ImageType::AnimatedWebP
 | 
			
		||||
                } else {
 | 
			
		||||
                    ImageType::WebP
 | 
			
		||||
                }
 | 
			
		||||
            })
 | 
			
		||||
        }
 | 
			
		||||
        _ => Ok(ImageType::Unsupported),
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// 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
 | 
			
		||||
| 
						 | 
				
			
			@ -70,13 +70,11 @@ fn is_animated_webp(file_path: &std::path::Path) -> Result<bool, String> {
 | 
			
		|||
        .map(|anim| anim.has_animation())
 | 
			
		||||
        .map_err(|_| "File is not a valid WebP image".to_string())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn main() {
 | 
			
		||||
    // Example usage
 | 
			
		||||
    let path = std::path::Path::new("/home/vomitblood/Downloads/Win10_22H2_English_x64v1.iso");
 | 
			
		||||
    match is_animated_webp(path) {
 | 
			
		||||
        Ok(true) => println!("The WebP is animated."),
 | 
			
		||||
        Ok(false) => println!("The WebP is not animated."),
 | 
			
		||||
        Err(e) => println!("Error: {}", e),
 | 
			
		||||
    let path = std::path::Path::new("path/to/your/image.webp");
 | 
			
		||||
    match determine_image_type(&path) {
 | 
			
		||||
        Ok(image_type) => println!("Image type: {:?}", image_type),
 | 
			
		||||
        Err(e) => println!("Error determining image type: {}", e),
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue