Skip to content

Commit

Permalink
add sh as code file extension
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianRzk committed Jan 22, 2025
1 parent ac607c2 commit 44c610a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion backend/src/io/fs/asset_cache_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ pub fn load_cachable_asset(
content: read_file(abs_path),
});
}
return AssetState::NotFound;
AssetState::NotFound
}
4 changes: 1 addition & 3 deletions backend/src/io/fs/basic_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use std::fs;
use std::fs::Metadata;
use std::path::PathBuf;

const NULL_BYTE: &str = "\0";

pub fn read_file(path: PathBuf) -> String {
println!("loading file {}", path.to_str().unwrap());
fs::read_to_string::<PathBuf>(path).unwrap()
Expand Down Expand Up @@ -46,7 +44,7 @@ pub fn delete_file(path: PathBuf) {

pub fn is_text_file(path: PathBuf) -> bool {
let file_content = read_binary_file(path);
!file_content.contains(&NULL_BYTE.as_bytes()[0])
!(file_content.contains(&b'\x00') || file_content.contains(&b'\xff'))
}

pub fn delete_all_forbidden_chars_in_filename(filename: String) -> String {
Expand Down
38 changes: 20 additions & 18 deletions backend/src/looksyk/media/media_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,6 @@ pub enum MediaType {
Pdf,
}

pub fn get_media_type_from_extension(asset_descriptor: &AssetDescriptor) -> MediaType {
let extension = asset_descriptor.find_extension();
if extension.is_none() {
return MediaType::Other;
}

match extension.unwrap().to_lowercase().as_str() {
"mp4" | "webm" | "ogm" => MediaType::Video,
"jpg" | "jpeg" | "png" | "gif" | "webp" | "svg" => MediaType::Image,
"mp3" | "wav" | "flac" | "ogg" => MediaType::Audio,
"txt" => MediaType::Text,
"rs" | "py" | "js" | "css" | "java" | "kt" | "c" | "sql" | "go" | "php" => MediaType::Code,
"html" | "htm" => MediaType::Html,
"pdf" => MediaType::Pdf,
_ => MediaType::Other,
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -77,3 +59,23 @@ mod tests {
assert_eq!(result, MediaType::Other);
}
}

pub fn get_media_type_from_extension(asset_descriptor: &AssetDescriptor) -> MediaType {
let extension = asset_descriptor.find_extension();
if extension.is_none() {
return MediaType::Other;
}

match extension.unwrap().to_lowercase().as_str() {
"mp4" | "webm" | "ogm" => MediaType::Video,
"jpg" | "jpeg" | "png" | "gif" | "webp" | "svg" => MediaType::Image,
"mp3" | "wav" | "flac" | "ogg" => MediaType::Audio,
"txt" => MediaType::Text,
"rs" | "py" | "js" | "css" | "java" | "kt" | "c" | "sql" | "go" | "php" | "sh" => {
MediaType::Code
}
"html" | "htm" => MediaType::Html,
"pdf" => MediaType::Pdf,
_ => MediaType::Other,
}
}

0 comments on commit 44c610a

Please sign in to comment.