From 10587f48cbad42cb5ad9d544167a6b1eea4c060e Mon Sep 17 00:00:00 2001 From: Leeingnyo Date: Sun, 15 May 2022 16:03:15 +0900 Subject: [PATCH] Implement is_supported_image_file --- src/library/types.cr | 10 ---------- src/util/util.cr | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/library/types.cr b/src/library/types.cr index 973aa5e..d6a014f 100644 --- a/src/library/types.cr +++ b/src/library/types.cr @@ -1,13 +1,3 @@ -SUPPORTED_IMG_TYPES = %w( - image/jpeg - image/png - image/webp - image/apng - image/avif - image/gif - image/svg+xml -) - enum SortMethod Auto Title diff --git a/src/util/util.cr b/src/util/util.cr index e7b1b1a..7d834fb 100644 --- a/src/util/util.cr +++ b/src/util/util.cr @@ -3,6 +3,16 @@ ENTRIES_IN_HOME_SECTIONS = 8 UPLOAD_URL_PREFIX = "/uploads" STATIC_DIRS = %w(/css /js /img /webfonts /favicon.ico /robots.txt) SUPPORTED_FILE_EXTNAMES = [".zip", ".cbz", ".rar", ".cbr"] +SUPPORTED_IMG_TYPES = %w( + image/jpeg + image/png + image/webp + image/apng + image/avif + image/gif + image/svg+xml +) + def random_str UUID.random.to_s.gsub "-", "" @@ -49,6 +59,10 @@ def is_supported_file(path) SUPPORTED_FILE_EXTNAMES.includes? File.extname(path).downcase end +def is_supported_image_file(path) + SUPPORTED_IMG_TYPES.includes? MIME.from_filename? path +end + struct Int def or(other : Int) if self == 0