From 2bfa19fe24d545eff60dd5c87a06cd161afcf043 Mon Sep 17 00:00:00 2001 From: Sheldon Lee Date: Mon, 13 Nov 2023 22:47:14 +0800 Subject: [PATCH] Slight refactoring --- php/get.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/php/get.php b/php/get.php index 91d046c..04cfc9f 100644 --- a/php/get.php +++ b/php/get.php @@ -24,8 +24,6 @@ define("VIDEO_EXTENSIONS", [ define("FILE_EXTENSIONS", array_merge(IMAGE_EXTENSIONS, VIDEO_EXTENSIONS)); -main(); - function main(): void { $data = json_decode(file_get_contents('php://input'), true); $array = []; @@ -42,15 +40,17 @@ function main(): void { $is_dir = is_dir(ROOT_DIR.IMG_DIR.$path); if (!$is_dir && !is_valid_file_type($file)) continue; + $url = ROOT_URL.IMG_DIR.$path; + $thumbnail_url = null; + + if (!$is_dir) { + $thumbnail_url = create_thumbnail($category, $file); + } + $file_item = []; $file_item["is_dir"] = $is_dir; - if ($is_dir) { - $file_item["url"] = ROOT_URL.IMG_DIR.$path; - $file_item["thumbnail_url"] = null; - } else { - $file_item["url"] = ROOT_URL.IMG_DIR.$path; - $file_item["thumbnail_url"] = create_thumbnail($category, $file); - } + $file_item["url"] = $url; + $file_item["thumbnail_url"] = $thumbnail_url; array_push($array, $file_item); } @@ -67,7 +67,7 @@ function create_thumbnail(string $category, string $file): string | null { $thumbnail_file = $thumbnail_directory.$file; if (file_exists($thumbnail_file)) { - log_print("$thumbnail_file exists, skipping gneeration"); + log_print("$thumbnail_file exists, skipping generation"); goto return_thumbnail; } @@ -108,5 +108,6 @@ function is_image_file_type(string $filename): bool { } return false; } -?> +main(); +?>